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

Compiler warnings on Debian 7 (Wheezy) #255

Closed
ghost opened this issue Oct 1, 2017 · 3 comments
Closed

Compiler warnings on Debian 7 (Wheezy) #255

ghost opened this issue Oct 1, 2017 · 3 comments

Comments

@ghost
Copy link

ghost commented Oct 1, 2017

gcc-4.7.real (Debian 4.7.2-5) 4.7.2 with dpkg-buildflags

CFLAGS=-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security
CPPFLAGS=-D_FORTIFY_SOURCE=2
CXXFLAGS=-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security
FFLAGS=-g -O2
LDFLAGS=-Wl,-z,relro

shows:

gcc -DHAVE_CONFIG_H -I.  -D_GNU_SOURCE  -D_FORTIFY_SOURCE=2 -Wall -Werror -Wextra -g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -c -o pick-pick.o `test -f 'pick.c' || echo './'`pick.c
pick.c: In function ‘xmbtowc’:
pick.c:1109:9: error: ignoring return value of ‘mbtowc’, declared with attribute warn_unused_result [-Werror=unused-result]

... looking at the code:

        n = mbtowc(wc, s, MB_CUR_MAX);
        if (n == -1) {
                mbtowc(NULL, NULL, MB_CUR_MAX);
                return 0;
        }

I don't understand why the second call to mbtowc is required here ...

@mptre
Copy link
Owner

mptre commented Oct 1, 2017

I don't understand why the second call to mbtowc is required here ...

When in doubt, consult the manual; quoting mbtowc(3):

If a call to mbtowc() resulted in an undefined internal state,
mbtowc() must be called with s set to NULL to reset the internal state
before it can safely be used again.

Does a void suppress the warning?

diff --git pick.c pick.c
index d318a43..6ab2d9b 100644
--- pick.c
+++ pick.c
@@ -1106,7 +1106,7 @@ xmbtowc(wchar_t *wc, const char *s)
 
 	n = mbtowc(wc, s, MB_CUR_MAX);
 	if (n == -1) {
-		mbtowc(NULL, NULL, MB_CUR_MAX);
+		(void)mbtowc(NULL, NULL, MB_CUR_MAX);
 		return 0;
 	}

@ghost
Copy link
Author

ghost commented Oct 1, 2017

When in doubt, consult the manual; quoting mbtowc(3)

Sorry, but the paragraph you quoted is not in the manual here ...

Does a void suppress the warning?

No, but:

diff --git a/pick.c b/pick.c
index d318a43..28d0494 100644
--- a/pick.c
+++ b/pick.c
@@ -1106,7 +1106,7 @@ xmbtowc(wchar_t *wc, const char *s)
 
        n = mbtowc(wc, s, MB_CUR_MAX);
        if (n == -1) {
-               mbtowc(NULL, NULL, MB_CUR_MAX);
+               n = mbtowc(NULL, NULL, MB_CUR_MAX);
                return 0;
        }
 

mptre added a commit that referenced this issue Oct 1, 2017
In an attempt to reproduce the error in PR #255.
mptre added a commit that referenced this issue Oct 1, 2017
Fixes an issue discovered while compiling using GCC 4.7 on Debian 7 by
Jenz Guenther in #255.
@mptre
Copy link
Owner

mptre commented Oct 1, 2017

Thanks, commited in 274969a.

@mptre mptre closed this as completed Oct 1, 2017
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

1 participant