diff mbox series

[v4l-utils,v1] v4l2-tracer: fix trace path name creation

Message ID 20230330143635.17991-1-ps.report@gmx.net
State New
Headers show
Series [v4l-utils,v1] v4l2-tracer: fix trace path name creation | expand

Commit Message

Peter Seiderer March 30, 2023, 2:36 p.m. UTC
Fix trace path name creation for poor man's development boards
(e.g. Raspberry Pi) without RTC (starting at unix epoche aka time 0)
by forcing initial trace_id creation with 6 valid digits.

Fixes:

  terminate called after throwing an instance of 'std::out_of_range'
    what():  basic_string::substr: __pos (which is 5) > this->size() (which is 3)
  Aborted

Signed-off-by: Peter Seiderer <ps.report@gmx.net>
---
 utils/v4l2-tracer/v4l2-tracer.cpp | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/utils/v4l2-tracer/v4l2-tracer.cpp b/utils/v4l2-tracer/v4l2-tracer.cpp
index cb873d83..1a9a7d75 100644
--- a/utils/v4l2-tracer/v4l2-tracer.cpp
+++ b/utils/v4l2-tracer/v4l2-tracer.cpp
@@ -241,11 +241,9 @@  int tracer(int argc, char *argv[], bool retrace)
 		trace_id = json_file_name.substr(0, json_file_name.find(".json"));
 		trace_id += "_retrace";
 	} else {
-		const int timestamp_start_pos = 5;
-		trace_id = std::to_string(time(nullptr));
-		// trace_id = trace_id.substr(timestamp_start_pos, std::string::npos) + "_trace";
+		const int timestamp_start_pos = 1;
+		trace_id = std::to_string(100000 + time(nullptr) % 100000);
 		trace_id = trace_id.substr(timestamp_start_pos) + "_trace";
-
 	}
 	setenv("TRACE_ID", trace_id.c_str(), 0);
 	std::string trace_filename = trace_id + ".json";