Skip to content

Commit 962c8bd

Browse files
author
Thomas G. Lockhart
committed
Accept additional values for TRUE: y, Y, 1.
Leave all other input values to return FALSE. In next version, do more checking for valid inputs for both TRUE and FALSE.
1 parent 9c800b8 commit 962c8bd

File tree

1 file changed

+42
-8
lines changed

1 file changed

+42
-8
lines changed

src/backend/utils/adt/bool.c

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.7 1997/10/09 05:06:12 thomas Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.8 1997/10/17 05:38:32 thomas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -24,16 +24,50 @@
2424
/*
2525
* boolin - converts "t" or "f" to 1 or 0
2626
*
27-
* Check explicitly for "true/TRUE" and allow any odd ASCII value to be "true".
28-
* This handles "true/false", "yes/no", "1/0". - thomas 1997-10-05
27+
* Check explicitly for "true/false" and TRUE/FALSE, 1/0, YES/NO.
28+
* Reject other values. - thomas 1997-10-05
29+
* For now, allow old behavior of everything FALSE if not TRUE.
30+
* After v6.2.1 release, then enable code to reject goofy values.
31+
* Also, start checking the entire string rather than just the first character.
32+
* - thomas 1997-10-16
33+
*
34+
* In the switch statement, check the most-used possibilities first.
2935
*/
3036
bool
3137
boolin(char *b)
3238
{
33-
if (b == NULL)
34-
elog(WARN, "Bad input string for type bool");
35-
return ((bool) (((*b) == 't') || ((*b) == 'T') || ((*b) & 1)));
36-
}
39+
switch(*b) {
40+
case 't':
41+
case 'T':
42+
return (TRUE);
43+
break;
44+
45+
case 'f':
46+
case 'F':
47+
return (FALSE);
48+
break;
49+
50+
case 'y':
51+
case 'Y':
52+
case '1':
53+
return (TRUE);
54+
break;
55+
56+
case 'n':
57+
case 'N':
58+
case '0':
59+
return (FALSE);
60+
break;
61+
62+
default:
63+
#if FALSE
64+
elog(WARN,"Invalid input string '%s'\n", b);
65+
#endif
66+
break;
67+
}
68+
69+
return (FALSE);
70+
} /* boolin() */
3771

3872
/*
3973
* boolout - converts 1 or 0 to "t" or "f"
@@ -46,7 +80,7 @@ boolout(bool b)
4680
*result = (b) ? 't' : 'f';
4781
result[1] = '\0';
4882
return (result);
49-
}
83+
} /* boolout() */
5084

5185
/*****************************************************************************
5286
* PUBLIC ROUTINES *

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy