Fix: lttng-gen-tp: only replace file extension
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Tue, 19 Sep 2017 16:08:33 +0000 (12:08 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 19 Sep 2017 17:05:46 +0000 (13:05 -0400)
Previous replace was done on the complete path. A path containing
.c or .o would result in a corrupted file path.

Reported-by: Gunnar Strand <Gunnar.Strand@ericsson.com>
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
tools/lttng-gen-tp

index b62cd9907618207de72604e947a3b0ab11df9558..6aa1bba15d05012cf75e8d3aa0af69d4efa67bdf 100755 (executable)
@@ -79,7 +79,9 @@ class CFile:
     def write(self):
         outputFile = open(self.outputFilename,"w")
 
-        headerFilename = self.outputFilename.replace(".c",".h")
+        headerFilename = self.outputFilename
+        if headerFilename.endswith(".c"):
+            headerFilename = headerFilename[:-2] + ".h"
 
         outputFile.write(CFile.FILE_TPL.format(
                                            headerFilename = headerFilename))
@@ -126,7 +128,10 @@ class ObjFile:
         return cc
 
     def write(self):
-        cFilename = self.outputFilename.replace(".o",".c")
+        cFilename = self.outputFilename
+        if cFilename.endswith(".o"):
+            cFilename = cFilename[:-2] + ".c"
+
         cc = self._detectCC()
         if cc == "":
             raise RuntimeError("No C Compiler detected")
This page took 0.025114 seconds and 4 git commands to generate.