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

invalid format string conversion in src/common.c #3026

Closed
jeffhammond opened this issue Jun 5, 2017 · 4 comments · Fixed by #3032
Closed

invalid format string conversion in src/common.c #3026

jeffhammond opened this issue Jun 5, 2017 · 4 comments · Fixed by #3032
Assignees

Comments

@jeffhammond
Copy link
Member

I dislike compiler warnings...

$ icc -std=gnu99 -DHAVE_CONFIG_H -I. -I.. -I../include -D_GNU_SOURCE -D__USE_XOPEN2K8 -DSYSCONFDIR=\"/home/jrhammon/NWCHEM/deps/etc\" -DRDMADIR=\"@rdmadir@\" -DPROVDLDIR=\"/home/jrhammon/NWCHEM/deps/lib/libfabric\" -I../prov/sockets/include -I../prov/sockets -Wall -fvisibility=hidden -O2 -DNDEBUG -Wall -Wundef -Wpointer-arith -MT src/src_libfabric_la-common.lo -MD -MP -MF src/.deps/src_libfabric_la-common.Tpo -c ../src/common.c  -fPIC -DPIC -o src/.libs/src_libfabric_la-common.o
../src/common.c(305): warning #269: invalid format string conversion
  	ret = sscanf(str, "%m[^:]://", &fmt);
  	                               ^

../src/common.c(354): warning #269: invalid format string conversion
  	ret = sscanf(str, "%*[^:]://%m[^:]:%" SCNu16, &ip, &sin->sin_port);
  	                                              ^

../src/common.c(358): warning #269: invalid format string conversion
  	ret = sscanf(str, "%*[^:]://%m[^:/]", &ip);
  	                                      ^

../src/common.c(394): warning #269: invalid format string conversion
  	ret = sscanf(str, "%*[^:]://[%m[^]]]:%" SCNu16, &ip, &sin6->sin6_port);
  	                                                ^

../src/common.c(398): warning #269: invalid format string conversion
  	ret = sscanf(str, "%*[^:]://[%m[^]]", &ip);
  	                                      ^


Compiler Version

$ icc -v
icc version 17.0.4 (gcc version 4.8.5 compatibility)
@shefty
Copy link
Member

shefty commented Jun 5, 2017

Does icc not like the %m format?

@jeffhammond
Copy link
Member Author

It's not ISO C: https://stackoverflow.com/a/20577576/2189128.

The fix is easy enough. Just apply the definition found on http://www.gnu.org/software/libc/manual/html_node/Other-Output-Conversions.html:

Thus:

fprintf (stderr, "can't open %s': %m\n", filename);`

is equivalent to:

fprintf (stderr, "can't open %s': %s\n", filename, strerror (errno));`

@jeffhammond
Copy link
Member Author

And indeed, ICC will not compile this with -Werror when I used std=gnu11. I will file a compiler bug report w.r.t. ICC not providing full GCC compatibility here.

@shefty
Copy link
Member

shefty commented Jun 5, 2017

With sscanf, the %m allocates a buffer of an appropriate size. I can switch to using a fixed-size buffer, with checks to see that it doesn't get overrun (I think).

@shefty shefty self-assigned this Jun 5, 2017
shefty added a commit to shefty/libfabric that referenced this issue Jun 5, 2017
The code relies on a gcc extension to sscanf (%m) that isn't
available on other compilers (i.e. icc, even when gcc compliance
is enabled).  Replace %m will fixed sized buffers and check for
overrun.

Fixes ofiwg#3026

Signed-off-by: Sean Hefty <[email protected]>
shefty added a commit to shefty/libfabric that referenced this issue Jun 5, 2017
The code relies on a gcc extension to sscanf (%m) that isn't
available on other compilers (i.e. icc, even when gcc compliance
is enabled).  Replace %m will fixed sized buffers and check for
overrun.

Fixes ofiwg#3026

Signed-off-by: Sean Hefty <[email protected]>
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

Successfully merging a pull request may close this issue.

2 participants