diff options
author | Philip Chimento <philip.chimento@gmail.com> | 2019-09-07 21:32:08 -0700 |
---|---|---|
committer | Philip Chimento <philip.chimento@gmail.com> | 2019-09-15 13:42:49 -0700 |
commit | 1d47c3e3c9ce05f6fca9b76883fc27f24d65c526 (patch) | |
tree | f76b2ae848576ab935d928b06c12f9eaee010f6b /test/gjs-test-coverage.cpp | |
parent | 8176280293478b42fc08b83b4d42713464dff78b (diff) | |
download | gjs-1d47c3e3c9ce05f6fca9b76883fc27f24d65c526.tar.gz |
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.
Diffstat (limited to 'test/gjs-test-coverage.cpp')
-rw-r--r-- | test/gjs-test-coverage.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
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); |