From c2c8e40ff219f78779fc2743f0c1ffbabe159e37 Mon Sep 17 00:00:00 2001 From: Doug Szumski Date: Wed, 20 Jun 2018 20:57:33 +0100 Subject: [PATCH] Fix GCC 8 warning for input strings MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit As described in issue #293 GCC 8 fails the build in the current configuration on warnings like: sim/run_avr.c:193:4: error: ‘strncpy’ specified bound 128 equals destination size [-Werror=stringop-truncation] strncpy(f.tracename, argv[++pi], sizeof(f.tracename)); This isn't the only solution, but it get's the build working. --- simavr/sim/run_avr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/simavr/sim/run_avr.c b/simavr/sim/run_avr.c index d20bf75..3686ced 100644 --- a/simavr/sim/run_avr.c +++ b/simavr/sim/run_avr.c @@ -106,7 +106,7 @@ main( display_usage(basename(argv[0])); } else if (!strcmp(argv[pi], "-m") || !strcmp(argv[pi], "--mcu")) { if (pi < argc-1) - strncpy(name, argv[++pi], sizeof(name)); + snprintf(name, sizeof(name), "%s", argv[++pi]); else display_usage(basename(argv[0])); } else if (!strcmp(argv[pi], "-f") || !strcmp(argv[pi], "--freq")) { @@ -127,7 +127,7 @@ main( exit(1); } ++pi; - strncpy(f.tracename, argv[pi], sizeof(f.tracename)); + snprintf(f.tracename, sizeof(f.tracename), "%s", argv[pi]); } else if (!strcmp(argv[pi], "--add-vcd-trace")) { if (pi + 1 >= argc) { fprintf(stderr, "%s: missing mandatory argument for %s.\n", argv[0], argv[pi]); @@ -190,7 +190,7 @@ main( fprintf(stderr, "%s: missing mandatory argument for %s.\n", argv[0], argv[pi]); exit(1); } - strncpy(f.tracename, argv[++pi], sizeof(f.tracename)); + snprintf(f.tracename, sizeof(f.tracename), "%s", argv[++pi]); } else if (!strcmp(argv[pi], "-ti")) { if (pi < argc-1) trace_vectors[trace_vectors_count++] = atoi(argv[++pi]); -- 2.39.5