From: Doug Szumski Date: Wed, 20 Jun 2018 19:57:33 +0000 (+0100) Subject: Fix GCC 8 warning for input strings X-Git-Tag: v1.7~42^2 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=c2c8e40ff219f78779fc2743f0c1ffbabe159e37;p=sx%2Fsimavr.git Fix GCC 8 warning for input strings 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. --- 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]);