Skip to content

Compilation error with strncpy  #28

@iolalla

Description

@iolalla

In gcc (Ubuntu 11.2.0-7ubuntu2) 11.2.0 I had the following error while compiling:

In file included from /usr/include/string.h:519,
from /home/iolalla/src/pquery/src/third_party/inih++/lib/ini.c:12:
In function ‘strncpy’,
inlined from ‘strncpy0’ at /home/iolalla/src/pquery/src/third_party/inih++/lib/ini.c:55:3,
inlined from ‘ini_parse_file’ at /home/iolalla/src/pquery/src/third_party/inih++/lib/ini.c:143:9:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:95:10: error: ‘__builtin_strncpy’ output may be truncated copying 49 bytes from a string of length 199 [-Werror=stringop-truncation]
95 | return __builtin___strncpy_chk (__dest, __src, __len,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
96 | __glibc_objsize (__dest));
| ~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[2]: *** [src/third_party/inih++/lib/CMakeFiles/inih++.dir/build.make:82: src/third_party/inih++/lib/CMakeFiles/inih++.dir/ini.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:196: src/third_party/inih++/lib/CMakeFiles/inih++.dir/all] Error 2
make: *** [Makefile:171: all] Error 2

In order to fix it I changed strncpy with memcpy and compile smoothly:

diff --git a/src/third_party/inih++/lib/ini.c b/src/third_party/inih++/lib/ini.c
index 5228f0d..33d4691 100644
--- a/src/third_party/inih++/lib/ini.c
+++ b/src/third_party/inih++/lib/ini.c
@@ -52,7 +52,7 @@ static char* find_char_or_comment(const char* s, char c) {

/* Version of strncpy that ensures dest (size bytes) is null-terminated. /
static char
strncpy0(char* dest, const char* src, size_t size) {

  • strncpy(dest, src, size);
  • memcpy(dest, src, size);
    dest[size - 1] = '\0';
    return dest;
    }

If you prefer I can do a pull request

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions