mailing list of musl libc
 help / color / mirror / code / Atom feed
* Different scanf behaviour compared to glibc
@ 2017-07-07 19:53 Evgeni Stebaev
  2017-07-07 20:41 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: Evgeni Stebaev @ 2017-07-07 19:53 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 455 bytes --]

Hi!

sscanf returns 0 for the following code using musl, but glibc returns 1.
%15s cannot be used here since it stops on whitespace, but it's required to
get all remaining data after getting other fields with sscanf (not included
in this example).

#include <stdio.h>
#include <string.h>

int main(void) {
  char data[16];
  memset(data, '\0', sizeof(data));
  int res = sscanf("abcde", "%15c", data);
  printf("parse: %d %s\n", res, data);
  return 0;
}

[-- Attachment #2: Type: text/html, Size: 590 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Different scanf behaviour compared to glibc
  2017-07-07 19:53 Different scanf behaviour compared to glibc Evgeni Stebaev
@ 2017-07-07 20:41 ` Rich Felker
  0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2017-07-07 20:41 UTC (permalink / raw)
  To: musl

On Fri, Jul 07, 2017 at 10:53:34PM +0300, Evgeni Stebaev wrote:
> Hi!
> 
> sscanf returns 0 for the following code using musl, but glibc returns 1.
> %15s cannot be used here since it stops on whitespace, but it's required to
> get all remaining data after getting other fields with sscanf (not included
> in this example).
> 
> #include <stdio.h>
> #include <string.h>
> 
> int main(void) {
>   char data[16];
>   memset(data, '\0', sizeof(data));
>   int res = sscanf("abcde", "%15c", data);
>   printf("parse: %d %s\n", res, data);
>   return 0;
> }

This is a known glibc bug (at least #12701, maybe duplicated in
others) that they were historically unwilling to fix. musl's behavior
matches what's required by the C standard. You might be able to use %[
to achieve what you want.

Rich


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-07-07 20:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-07 19:53 Different scanf behaviour compared to glibc Evgeni Stebaev
2017-07-07 20:41 ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).