Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 15 Jan 1997 08:30:01 -0800 (PST)
From:      "John S. Dyson" <toor@dyson.iquest.net>
To:        freebsd-bugs
Subject:   Re: bin/2502: Unable to sscanf first integer value.
Message-ID:  <199701151630.IAA09731@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/2502; it has been noted by GNATS.

From: "John S. Dyson" <toor@dyson.iquest.net>
To: scrutchfield@ifusion.com
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: bin/2502: Unable to sscanf first integer value.
Date: Wed, 15 Jan 1997 11:21:26 -0500 (EST)

 > I am unable to sscanf correctly 2 integers from a string.  A Sample
 > program that recreates the problem is shown below.  This is a problem
 > in both libc and libc_r.
 > 
 > #include <stdio.h>
 > #include <string.h>
 > #include <stdlib.h>
 > 
 > main()
 > {
 > 	char *tmp = "999 12346";
 > 	char *ptr;
 > 	unsigned short x;
 > 	unsigned short y;
 > 	unsigned short z;
 > 	unsigned int a;
 > 	int result;
 > 
 > 	result = sscanf ( tmp, "%d %d", &x, &y );
 > 	z = strtol ( tmp, &ptr, 0 );
 > 	a = atoi ( tmp );
 > 	(void)fprintf ( stderr, "x(%d)y(%d)z(%d)a(%d)\n", x, y, z, a );
 > 	exit ( 0 );
 > }
 > 
 > >How-To-Repeat:
 > Run the above program.
 > >Fix:
 > 
 The problem that you are seeing is due to passing a pointer to
 a "short" instead of a pointer to an "int."  If you change the
 declarations of (x,y) to be "unsigned int", then things will work
 well.
 
 John



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199701151630.IAA09731>