Skip to Content.
Sympa Menu

freetds - RE: [freetds] A small fix

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Thompson, Bill D (London)" <bill_d_thompson AT ml.com>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: RE: [freetds] A small fix
  • Date: Fri, 10 Dec 2004 16:06:43 -0000

Thanks Freddy,

You've clearly understood what I've tried to do, and (as usual) improved
on it.
Feel free to apply your modified changes if you like - but tell James
before he applies mine.

Bill

-----Original Message-----
From: freetds-bounces AT lists.ibiblio.org
[mailto:freetds-bounces AT lists.ibiblio.org] On Behalf Of ZIGLIO,
Frediano, VF-IT
Sent: 10 December 2004 16:01
To: FreeTDS Development Group
Subject: RE: [freetds] A small fix


>
> Guys,
>
> If RC5 turns out NOT to be the final release, I've got a
> small patch to
> src/tds/convert.c
>
> This corrects some small bugs in string_to_numeric().
>
> as things stand we regard a string like
>
> ".1234"
>
> as being malformed.
> We also don't like trailing blanks on a string.
>
> here's the diff:
>
> --- convert.c 2004-10-14 15:47:39.000000000 +0100
> +++ /home/thompbil/FREETDS/freetds-0.63RC2.mine/src/tds/convert.c
> 2004-12-10 13:55:53.099889000 +0000
> @@ -1974,11 +1974,12 @@
> char not_zero = 1;
> int i = 0;
> int j = 0;
> - short int bytes, places, point_found, digits;
> + short int bytes, places, point_found, space_found, digits;
> unsigned char sign;
>
> sign = 0;
> point_found = 0;
> + space_found = 0;
> places = 0;
>
> /* FIXME: application can pass invalid value for precision and
> scale ?? */
> @@ -2010,6 +2011,8 @@
> pdigits = pstr;
> for (; pstr != pend; ++pstr) { /* deal with the rest */
> if (isdigit((unsigned char) *pstr)) { /*
> its a number
> */
> + if (space_found)
> + return TDS_CONVERT_SYNTAX; /*
> return error. */
> if (point_found) /* if we passed a
> decimal point */
> ++places; /* count digits after
> that point */
> else
> @@ -2017,13 +2020,17 @@
> } else if (*pstr == '.') { /* found a
> decimal point
> */
> if (point_found) /* already had one.
> return error */
> return TDS_CONVERT_SYNTAX;
> + if (space_found)
> + return TDS_CONVERT_SYNTAX; /*
> return error. */
> point_found = 1;
> + } else if (*pstr == ' ') {
> + space_found = 1;
> } else /* first invalid character */
> return TDS_CONVERT_SYNTAX; /*
> return error.
> */
> }
>
> /* no digits? no number! */
> - if (!digits)
> + if (!digits && !point_found)
> return TDS_CONVERT_SYNTAX;
>
> /* truncate decimal digits */

Mmmm... should work but it accept even " . " syntax...
Perhaps another patch it's to change test from

if (!digits)

do

if (digits + places == 0)

and last if from

} else /* first invalid character */
return TDS_CONVERT_SYNTAX;

to

} else { /* first invalid character */
while( pstr != pend && *pstr == ' ')
++pstr;
if (pstr == pend)
break;
return TDS_CONVERT_SYNTAX;
}

So we avoid also a new variable (with all optimizations problems that
can raise)

freddy77
_______________________________________________
FreeTDS mailing list
FreeTDS AT lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/freetds
--------------------------------------------------------

If you are not an intended recipient of this e-mail, please notify the
sender, delete it and do not read, act upon, print, disclose, copy, retain or
redistribute it. Click here for important additional terms relating to this
e-mail. http://www.ml.com/email_terms/
--------------------------------------------------------





Archive powered by MHonArc 2.6.24.

Top of Page