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: "ZIGLIO, Frediano, VF-IT" <Frediano.Ziglio AT vodafone.com>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: RE: [freetds] A small fix
  • Date: Fri, 10 Dec 2004 17:00:49 +0100

>
> 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




Archive powered by MHonArc 2.6.24.

Top of Page