Commit c2c8e40ff219f78779fc2743f0c1ffbabe159e37
authorDoug Szumski <d.s.szumski@gmail.com>
Wed, 20 Jun 2018 19:57:33 +0000 (20:57 +0100)
committerDoug Szumski <d.s.szumski@gmail.com>
Wed, 20 Jun 2018 20:28:50 +0000 (21:28 +0100)
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

index d20bf757f263aea037cb27159e96cfd6482cc1c4..3686ced04c3306b53141ae1826248ee3eeb2374e 100644 (file)
@@ -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]);