Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation error with strncpy #28

Open
iolalla opened this issue Dec 5, 2021 · 5 comments
Open

Compilation error with strncpy #28

iolalla opened this issue Dec 5, 2021 · 5 comments

Comments

@iolalla
Copy link

iolalla commented Dec 5, 2021

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

@RoelVdP
Copy link
Contributor

RoelVdP commented Mar 9, 2023

@mohitj1988 Hi! Can you please fix this in the repo? I think you ran into similar in pstress? Thanks

@RoelVdP
Copy link
Contributor

RoelVdP commented Mar 9, 2023

While at it, please also have a look at #27 if it is correct, and other open tickets. Thank you.

@mohitj1988
Copy link

mohitj1988 commented Mar 10, 2023

Hi @RoelVdP - This was fixed in pstress a while ago. The commit ID: a4fbeb3.
I will fix it in pquery as well

@RoelVdP
Copy link
Contributor

RoelVdP commented Mar 10, 2023

Yes, I am aware. Thank you!

@RoelVdP
Copy link
Contributor

RoelVdP commented Mar 10, 2023

Btw, I thought there was some feedback that the memcpy introduced a new bug?
See benhoyt/inih#104 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants