poppler/Form.cc |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 4b6a530539bb29ac057d2ac6d8f74d2ca78a3f2a
Author: Even Rouault <even.roua...@spatialys.com>
Date:   Wed Nov 24 15:46:09 2021 +0100

    Form.cc: fix -Wstringop-truncation warning
    
    gcc 9.3.0 (Ubuntu 20.04) with CMAKE_BUILD_TYPE=Debug emits
    ```
    /usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:34: warning: 
‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ output may be 
truncated copying 10 bytes from a string of length 49 [-Wstringop-truncation]
      106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos 
(__dest));
          |          
~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ```
    
    In that situation this is a false positive. But using memcpy() makes
    things clearer as the copied string cannot be shorter than 10 bytes due
    to how it is composed before (an integer value followed by more than 10
    spaces).

diff --git a/poppler/Form.cc b/poppler/Form.cc
index 9bef701c..c7b44fee 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -684,7 +684,7 @@ static char *setNextOffset(char *start, Goffset offset)
 
     char *p = strstr(start, "9999999999");
     if (p) {
-        strncpy(p, buf, 10); // overwrite exact size.
+        memcpy(p, buf, 10); // overwrite exact size.
         p += 10;
     } else {
         return nullptr;

Reply via email to