shithub: jbig2

Download patch

ref: 17246f7e4d281334b4f185e157e23491cd70f73e
parent: 483249ce08125a738fcae44fe59f9ef5ef0cb023
author: Sebastian Rasmussen <[email protected]>
date: Tue Oct 1 14:08:34 EDT 2019

jbig2dec: Avoid warning by copying bytes instead of characters.

--- a/jbig2dec.c
+++ b/jbig2dec.c
@@ -458,6 +458,7 @@
 {
     char *output_filename;
     const char *c, *e;
+    int extlen;
     int len;
 
     if (extension == NULL) {
@@ -488,16 +489,18 @@
     if (e != NULL)
         len -= strlen(e);
 
+    extlen = strlen(extension);
+
     /* allocate enough space for the base + ext */
-    output_filename = (char *)malloc(len + strlen(extension) + 1);
+    output_filename = (char *)malloc(len + extlen + 1);
     if (output_filename == NULL) {
         fprintf(stderr, "failed to allocate memory for output filename\n");
         exit(1);
     }
 
-    strncpy(output_filename, c, len);
-    strncpy(output_filename + len, extension, strlen(extension));
-    *(output_filename + len + strlen(extension)) = '\0';
+    memcpy(output_filename, c, len);
+    memcpy(output_filename + len, extension, extlen);
+    *(output_filename + len + extlen) = '\0';
 
     /* return the new string */
     return (output_filename);