[PATCHES] reject empty string in float[48], oid

2005-02-10 Thread Neil Conway
This patch changes the input routines for float4, float8 and oid to
reject empty strings (rather than treating them as 0). In 8.0 we issue
a warning about this behavior and indicate that the input will not be
accepted by a future release, so it seems reasonable to disallow the
input in 8.1. The patch also updates the regression tests.

Barring any objections, I'll apply this to HEAD tomorrow.

-Neil

Index: src/backend/utils/adt/float.c
===
RCS file: /var/lib/cvs/pgsql/src/backend/utils/adt/float.c,v
retrieving revision 1.112
diff -c -r1.112 float.c
*** src/backend/utils/adt/float.c	31 Dec 2004 22:01:21 -	1.112
--- src/backend/utils/adt/float.c	11 Feb 2005 01:10:19 -
***
*** 267,287 
  	/*
  	 * Check for an empty-string input to begin with, to avoid the
  	 * vagaries of strtod() on different platforms.
- 	 *
- 	 * In releases prior to 8.0, we accepted an empty string as valid input
- 	 * (yielding a float4 of 0). In 8.0, we accept empty strings, but emit
- 	 * a warning noting that the feature is deprecated. In 8.1+, the
- 	 * warning should be replaced by an error.
  	 */
  	if (*num == '\0')
! 	{
! 		ereport(WARNING,
! (errcode(ERRCODE_WARNING_DEPRECATED_FEATURE),
!  errmsg(deprecated input syntax for type real: \\),
!  errdetail(This input will be rejected in 
! 		   a future release of PostgreSQL.)));
! 		PG_RETURN_FLOAT4((float4) 0.0);
! 	}
  
  	/* skip leading whitespace */
  	while (*num != '\0'  isspace((unsigned char) *num))
--- 267,278 
  	/*
  	 * Check for an empty-string input to begin with, to avoid the
  	 * vagaries of strtod() on different platforms.
  	 */
  	if (*num == '\0')
! 		ereport(ERROR,
! (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
!  errmsg(invalid input syntax for type real: \%s\,
! 		orig_num)));
  
  	/* skip leading whitespace */
  	while (*num != '\0'  isspace((unsigned char) *num))
***
*** 444,464 
  	/*
  	 * Check for an empty-string input to begin with, to avoid the
  	 * vagaries of strtod() on different platforms.
- 	 *
- 	 * In releases prior to 8.0, we accepted an empty string as valid input
- 	 * (yielding a float8 of 0). In 8.0, we accept empty strings, but emit
- 	 * a warning noting that the feature is deprecated. In 8.1+, the
- 	 * warning should be replaced by an error.
  	 */
  	if (*num == '\0')
! 	{
! 		ereport(WARNING,
! (errcode(ERRCODE_WARNING_DEPRECATED_FEATURE),
! 		errmsg(deprecated input syntax for type double precision: \\),
!  errdetail(This input will be rejected in 
! 		   a future release of PostgreSQL.)));
! 		PG_RETURN_FLOAT8(0.0);
! 	}
  
  	/* skip leading whitespace */
  	while (*num != '\0'  isspace((unsigned char) *num))
--- 435,446 
  	/*
  	 * Check for an empty-string input to begin with, to avoid the
  	 * vagaries of strtod() on different platforms.
  	 */
  	if (*num == '\0')
! 		ereport(ERROR,
! (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
!  errmsg(invalid input syntax for type double precision: \%s\,
! 		orig_num)));
  
  	/* skip leading whitespace */
  	while (*num != '\0'  isspace((unsigned char) *num))
Index: src/backend/utils/adt/oid.c
===
RCS file: /var/lib/cvs/pgsql/src/backend/utils/adt/oid.c,v
retrieving revision 1.60
diff -c -r1.60 oid.c
*** src/backend/utils/adt/oid.c	31 Dec 2004 22:01:22 -	1.60
--- src/backend/utils/adt/oid.c	11 Feb 2005 01:09:14 -
***
*** 33,50 
  	char	   *endptr;
  	Oid			result;
  
- 	/*
- 	 * In releases prior to 8.0, we accepted an empty string as valid
- 	 * input (yielding an OID of 0). In 8.0, we accept empty strings, but
- 	 * emit a warning noting that the feature is deprecated. In 8.1+, the
- 	 * warning should be replaced by an error.
- 	 */
  	if (*s == '\0')
! 		ereport(WARNING,
! (errcode(ERRCODE_WARNING_DEPRECATED_FEATURE),
!  errmsg(deprecated input syntax for type oid: \\),
!  errdetail(This input will be rejected in 
! 		   a future release of PostgreSQL.)));
  
  	errno = 0;
  	cvt = strtoul(s, endptr, 10);
--- 33,43 
  	char	   *endptr;
  	Oid			result;
  
  	if (*s == '\0')
! 		ereport(ERROR,
! (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
!  errmsg(invalid input syntax for type oid: \%s\,
! 		s)));
  
  	errno = 0;
  	cvt = strtoul(s, endptr, 10);
Index: src/test/regress/expected/float4-exp-three-digits.out
===
RCS file: /var/lib/cvs/pgsql/src/test/regress/expected/float4-exp-three-digits.out,v
retrieving revision 1.5
diff -c -r1.5 float4-exp-three-digits.out
*** src/test/regress/expected/float4-exp-three-digits.out	15 Mar 2004 16:20:51 -	1.5
--- src/test/regress/expected/float4-exp-three-digits.out	11 Feb 2005 01:17:06 -
***
*** 31,36 
--- 31,38 
  ERROR:  invalid input syntax for type real:  - 

Re: [PATCHES] reject empty string in float[48], oid

2005-02-10 Thread Tom Lane
Neil Conway [EMAIL PROTECTED] writes:
 This patch changes the input routines for float4, float8 and oid to
 reject empty strings (rather than treating them as 0). In 8.0 we issue
 a warning about this behavior and indicate that the input will not be
 accepted by a future release, so it seems reasonable to disallow the
 input in 8.1. The patch also updates the regression tests.

If you're going to add regression tests, how about testing the case of a
non-empty-but-all-whitespace string?

regards, tom lane

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [PATCHES] reject empty string in float[48], oid

2005-02-10 Thread Tom Lane
Neil Conway [EMAIL PROTECTED] writes:
 On Thu, 2005-02-10 at 20:53 -0500, Tom Lane wrote:
 If you're going to add regression tests, how about testing the case of a
 non-empty-but-all-whitespace string?

 AFAICS that is already tested for.

[ looks again... ]  Doh.  Maybe you should put these tests next to those
then...

regards, tom lane

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]


Re: [PATCHES] reject empty string in float[48], oid

2005-02-10 Thread Neil Conway
On Thu, 2005-02-10 at 21:04 -0500, Tom Lane wrote:
 Maybe you should put these tests next to those then...

Ok, fair enough. Patch applied to HEAD.

-Neil



---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq