Re: strtod sscanf on -CURRENT?

2002-05-26 Thread Igor Roboul

On Fri, May 24, 2002 at 12:13:37PM -0700, Alfred Perlstein wrote:
 
 You forgot to include stdlib.h.
But what's wrong with my test? strtod works Ok but sscanf does not. 
pre-gcc3.1 sscanf and sscanf on -STABLE work as expected.

-- 
Igor Roboul, System administrator at Speech Technology Center
http://www.speechpro.com http://www.speechpro.ru

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



strtod sscanf on -CURRENT?

2002-05-24 Thread Igor Roboul

Hello, 
I have some trouble with PostgreSQL on -CURRENT:

SELECT birth_date,date_part('year',birth_date)::varchar from employee
where id=132;
 birth_date | date_part  
+
 1974-05-09 | 0.046113777160645
(1 row)

This works as expected on -STABLE

I have made simple test:
%cat qq.c 
#include stdlib.h
main(int argc,char**argv)
{
double a;
char bb[100];

strcpy(bb,argv[1]);
printf(%lf\n,strtod(bb,NULL));
sscanf(argv[1],%lf,a);
printf(%lf\n,a);
}
%uname -a
FreeBSD sysadm.stc 5.0-CURRENT FreeBSD 5.0-CURRENT #9: Mon May 20
17:34:23 MSD 2002
[EMAIL PROTECTED]:/opt/freebsd/obj/opt/freebsd/src/sys/SYSADM  i386
%./a.out 1234.3124
1234.312400
0.124862

%uname -a
FreeBSD r1.stc 4.4-STABLE FreeBSD 4.4-STABLE #0: Tue Dec 25 15:02:18
MSK 2001 [EMAIL PROTECTED]:/usr/obj/usr/src/sys/R1  i386
%./a.out 1234.3124
1234.312400
1234.312400

Maybe I'm wrong, but I think that sscanf on -CURRENT does not work as
expected.

-- 
Igor Roboul, System administrator at Speech Technology Center
http://www.speechpro.com http://www.speechpro.ru

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: strtod sscanf on -CURRENT?

2002-05-24 Thread Chris Hedley

On Fri, 24 May 2002, Igor Roboul wrote:
 Maybe I'm wrong, but I think that sscanf on -CURRENT does not work as
 expected.

Interestingly I had some aggro with both scanf and strtod returning
somewhat random results recently (about 5th/6th May); I'm afraid I no
longer have the results or test programs but I ended up having to hack my
own routine together to get a reliable input.  What I seem to recall is
that scanf didn't return the correct result at all, whereas strtod was
okay for the first couple of invocations within the same program, after
which it began to return garbage (I'm pretty confident that my program
didn't have a buffer overrun, it was a fairly short  simple effort)

Chris.



To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: strtod sscanf on -CURRENT?

2002-05-24 Thread Mike Barcroft

Chris Hedley [EMAIL PROTECTED] writes:
 On Fri, 24 May 2002, Igor Roboul wrote:
  Maybe I'm wrong, but I think that sscanf on -CURRENT does not work as
  expected.
 
 Interestingly I had some aggro with both scanf and strtod returning
 somewhat random results recently (about 5th/6th May); I'm afraid I no
 longer have the results or test programs but I ended up having to hack my
 own routine together to get a reliable input.  What I seem to recall is
 that scanf didn't return the correct result at all, whereas strtod was
 okay for the first couple of invocations within the same program, after
 which it began to return garbage (I'm pretty confident that my program
 didn't have a buffer overrun, it was a fairly short  simple effort)

Would it be possible for you to reproduce the source to a small
program that demonstrates the problem?

Best regards,
Mike Barcroft

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: strtod sscanf on -CURRENT?

2002-05-24 Thread Chris Hedley

On Fri, 24 May 2002, Mike Barcroft wrote:
 Would it be possible for you to reproduce the source to a small
 program that demonstrates the problem?

Okay, here's a cheap'n'nasty program to demonstrate the problem; the
revised problem seems to be that strtod() is okay with integers but if a
period is present in the value passed to it, it returns the count of the
digits after the period, rather oddly:

#include stdio.h

main()
{   char buf[80], *eol;
double a;

while(1) {
printf( );
if(!fgets(buf, sizeof buf, stdin) ||
   tolower(buf[0]) == 'q') exit(0);
if(eol = strchr(buf, '\n')) *eol = 0;

a = strtod(buf, 0);
printf(buf=%s val=%7.2f\n, buf, a);
}
}

results:

=== uname -a
FreeBSD teabag.cbhnet 5.0-CURRENT FreeBSD 5.0-CURRENT #10: Thu May 16
15:40:46 BST 2002 [EMAIL PROTECTED]:/usr/obj/usr/src/sys/TEABAG  i386
=== ./a
 324
buf=324 val= 324.00
 1
buf=1 val=   1.00
 1.2
buf=1.2 val=   1.00
 2.1
buf=2.1 val=   1.00
 22.53
buf=22.53 val=   2.00
 123.45
buf=123.45 val=   2.00
 4216.6547
buf=4216.6547 val=   4.00
 23513.63462
buf=23513.63462 val=   5.00
 23.53256
buf=23.53256 val=   5.00
 5432.63426abcde
buf=5432.63426abcde val=   5.00
 q

Now I'm not discounting that I've overlooked something really obvious or
have done something stupid with my test and original programs, but I can't
think what it is if this is the case!

Chris.


To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: strtod sscanf on -CURRENT?

2002-05-24 Thread Chris Hedley

On Fri, 24 May 2002, Chris Hedley wrote:
 Now I'm not discounting that I've overlooked something really obvious or
 have done something stupid with my test and original programs, but I can't
 think what it is if this is the case!

Right, anybody in my locality is now welcome to come and slap me around
the face with a wet fish for not including the header file with the
function prototype in it.  Obviously I needed to make a fool of myself in
public before immediately discovering the error of my ways.  Sorry, all.

Chris.


To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: strtod sscanf on -CURRENT?

2002-05-24 Thread Alfred Perlstein

* Chris Hedley [EMAIL PROTECTED] [020524 10:53] wrote:
 On Fri, 24 May 2002, Mike Barcroft wrote:
  Would it be possible for you to reproduce the source to a small
  program that demonstrates the problem?
 
 Okay, here's a cheap'n'nasty program to demonstrate the problem; the
 revised problem seems to be that strtod() is okay with integers but if a
 period is present in the value passed to it, it returns the count of the
 digits after the period, rather oddly:

You forgot to include stdlib.h.

Please compile things with -Wall before reporting weirdness on
the lists.

~ % gcc -Wall t.c
t.c:4: warning: return type defaults to `int'
t.c: In function `main':
t.c:10: warning: implicit declaration of function `tolower'
t.c:10: warning: implicit declaration of function `exit'
t.c:11: warning: implicit declaration of function `strchr'
t.c:11: warning: suggest parentheses around assignment used as truth value
t.c:13: warning: implicit declaration of function `strtod'


That's from the code you posted, scary what can happen and how much
of waste of your and our time this was. :)

-- 
-Alfred Perlstein [[EMAIL PROTECTED]]
'Instead of asking why a piece of software is using 1970s technology,
 start asking why software is ignoring 30 years of accumulated wisdom.'
Tax deductible donations for FreeBSD: http://www.freebsdfoundation.org/

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message