[gjs: 1/15] tests: Fix one remaining cppcheck error



commit 1d47c3e3c9ce05f6fca9b76883fc27f24d65c526
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Sep 7 21:32:08 2019 -0700

    tests: Fix one remaining cppcheck error
    
    sscanf() is basically unsafe to use, but here we are parsing well-formed
    LCov data in the test suite, so there's no user input involved. We can
    assume that source files in the test data have 99999 lines or fewer, and
    we dynamically generate the field width for the function name to fit the
    buffer we have allocated.

 test/gjs-test-coverage.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
---
diff --git a/test/gjs-test-coverage.cpp b/test/gjs-test-coverage.cpp
index d477d5ec..78ed0dd3 100644
--- a/test/gjs-test-coverage.cpp
+++ b/test/gjs-test-coverage.cpp
@@ -792,7 +792,8 @@ hit_count_is_more_than_for_function(const char *line,
 
     max_buf_size = strcspn(line, "\n");
     detected_function = g_new(char, max_buf_size + 1);
-    nmatches = sscanf(line, "%u,%s", &hit_count, detected_function);
+    GjsAutoChar format_string = g_strdup_printf("%%5u,%%%zus", max_buf_size);
+    nmatches = sscanf(line, format_string, &hit_count, detected_function);
     g_assert_cmpint(nmatches, ==, 2);
 
     g_assert_cmpstr(data->function, ==, detected_function);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]