]> git.neil.brown.name Git - wiggle.git/commitdiff
Fix format overflow and truncation warnings with GCC-8.
authorCarlos Maddela <e7appew@gmail.com>
Thu, 24 Jan 2019 18:04:46 +0000 (05:04 +1100)
committerCarlos Maddela <e7appew@gmail.com>
Thu, 24 Jan 2019 18:32:16 +0000 (05:32 +1100)
extract.c
vpatch.c

index a8068d234bd12efcf28e0e562677808961ad594d..c3c47e679f486def577793a17611584a9cbcd002 100644 (file)
--- a/extract.c
+++ b/extract.c
@@ -118,12 +118,17 @@ int split_patch(struct stream f, struct stream *f1, struct stream *f2)
                        skip_eol(&cp, end);
                        if (state == 1 || state == 3) {
                                char *f;
-                               char buf[20];
+                               int slen;
+                               /* Reserve enough space for 3 integers separated
+                                * by a single space, and prefixed and terminated
+                                * with a null character.
+                                */
+                               char buf[(3*12)+1];
                                buf[0] = 0;
                                chunks++;
-                               sprintf(buf+1, "%5d %5d %5d", chunks, a, acnt);
-                               memcpy(r1.body+r1.len, buf, 18);
-                               r1.len += 18;
+                               slen = sprintf(buf+1, "%5d %5d %5d", chunks, a, acnt)+1;
+                               memcpy(r1.body+r1.len, buf, slen);
+                               r1.len += slen;
                                f = func;
                                while (*f == ' ')
                                        f++;
@@ -136,11 +141,16 @@ int split_patch(struct stream f, struct stream *f1, struct stream *f2)
                                r1.body[r1.len++] = '\0';
                        }
                        if (state == 2 || state == 3) {
-                               char buf[20];
+                               int slen;
+                               /* Reserve enough space for 3 integers separated
+                                * by a single space, prefixed with a null character
+                                * and terminated with a new line and null character.
+                                */
+                               char buf[(3*12)+2];
                                buf[0] = 0;
-                               sprintf(buf+1, "%5d %5d %5d\n", chunks, c, bcnt);
-                               memcpy(r2.body+r2.len, buf, 20);
-                               r2.len += 20;
+                               slen = sprintf(buf+1, "%5d %5d %5d\n", chunks, c, bcnt)+2;
+                               memcpy(r2.body+r2.len, buf, slen);
+                               r2.len += slen;
                        }
                        if (state)
                                func[0] = 0;
index a6534a4462f17356d018924562b247ebc2d8bd7c..b735f36178f74bf0a646435e9ec35e9d0f0d79da 100644 (file)
--- a/vpatch.c
+++ b/vpatch.c
@@ -1680,8 +1680,8 @@ static int merge_window(struct plist *p, FILE *f, int reverse, int replace,
                        attrset(A_NORMAL);
                }
                if (num >= 0) {
-                       char buf[10];
-                       snprintf(buf, 10, "%d ", num);
+                       char buf[12+1];
+                       snprintf(buf, sizeof(buf), "%d ", num);
                        addstr(buf);
                }
                if (meta & META(0))
@@ -2487,7 +2487,7 @@ static int get_next(int pos, struct plist *pl, int n, int mode,
 static void draw_one(int row, struct plist *pl, FILE *f, int reverse,
                     int ignore_blanks, int just_diff)
 {
-       char hdr[12];
+       char hdr[2*12];
        hdr[0] = 0;
 
        if (pl == NULL) {