Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd9b01c1

Browse files
committed
Avoid failures in cash_out and cash_words for INT_MIN.
Also, 'fourty' -> 'forty'.
1 parenta2b4dbd commitd9b01c1

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

‎src/backend/utils/adt/cash.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* workings can be found in the book "Software Solutions in C" by
1010
* Dale Schumacher, Academic Press, ISBN: 0-12-632360-7.
1111
*
12-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.51 2001/10/25 05:49:43 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.52 2002/02/19 22:19:34 tgl Exp $
1313
*/
1414

1515
#include"postgres.h"
@@ -287,7 +287,7 @@ cash_out(PG_FUNCTION_ARGS)
287287
if (value<0)
288288
{
289289
minus=1;
290-
value*=-1;
290+
value=-value;
291291
}
292292

293293
/* allow for trailing negative strings */
@@ -301,8 +301,8 @@ cash_out(PG_FUNCTION_ARGS)
301301
elseif (comma&&count % (mon_group+1)==comma_position)
302302
buf[count--]=comma;
303303

304-
buf[count--]= (value %10)+'0';
305-
value/=10;
304+
buf[count--]= ((unsignedint)value %10)+'0';
305+
value= ((unsignedint)value) /10;
306306
}
307307

308308
strncpy((buf+count-strlen(csymbol)+1),csymbol,strlen(csymbol));
@@ -664,6 +664,7 @@ Datum
664664
cash_words(PG_FUNCTION_ARGS)
665665
{
666666
Cashvalue=PG_GETARG_CASH(0);
667+
unsignedintval;
667668
charbuf[128];
668669
char*p=buf;
669670
Cashm0;
@@ -682,10 +683,13 @@ cash_words(PG_FUNCTION_ARGS)
682683
else
683684
buf[0]='\0';
684685

685-
m0=value %100;/* cents */
686-
m1= (value /100) %1000;/* hundreds */
687-
m2= (value /100000) %1000;/* thousands */
688-
m3=value /100000000 %1000;/* millions */
686+
/* Now treat as unsigned, to avoid trouble at INT_MIN */
687+
val= (unsignedint)value;
688+
689+
m0=val %100;/* cents */
690+
m1= (val /100) %1000;/* hundreds */
691+
m2= (val /100000) %1000;/* thousands */
692+
m3=val /100000000 %1000;/* millions */
689693

690694
if (m3)
691695
{
@@ -705,7 +709,7 @@ cash_words(PG_FUNCTION_ARGS)
705709
if (!*p)
706710
strcat(buf,"zero");
707711

708-
strcat(buf, (int) (value /100)==1 ?" dollar and " :" dollars and ");
712+
strcat(buf, (val /100)==1 ?" dollar and " :" dollars and ");
709713
strcat(buf,num_word(m0));
710714
strcat(buf,m0==1 ?" cent" :" cents");
711715

@@ -733,7 +737,7 @@ num_word(Cash value)
733737
"zero","one","two","three","four","five","six","seven",
734738
"eight","nine","ten","eleven","twelve","thirteen","fourteen",
735739
"fifteen","sixteen","seventeen","eighteen","nineteen","twenty",
736-
"thirty","fourty","fifty","sixty","seventy","eighty","ninety"
740+
"thirty","forty","fifty","sixty","seventy","eighty","ninety"
737741
};
738742
constchar**big=small+18;
739743
inttu=value %100;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp