Fossil SCM

Fix a couple corner cases for the TH1 expr command.

mistachkin 2014-02-04 20:32 trunk
Commit e4e2b2e40e1707764115d250dcfd18ec66a2f6eb
2 files changed +14 -12 +65
+14 -12
--- src/th.c
+++ src/th.c
@@ -2002,27 +2002,29 @@
20022002
default: assert(!"Internal error");
20032003
}
20042004
Th_SetResultInt(interp, iRes);
20052005
}else if( rc==TH_OK && eArgType==ARG_NUMBER ){
20062006
switch( pExpr->pOp->eOp ) {
2007
- case OP_MULTIPLY: Th_SetResultDouble(interp, fLeft*fRight); break;
2007
+ case OP_MULTIPLY: Th_SetResultDouble(interp, fLeft*fRight); break;
20082008
case OP_DIVIDE:
20092009
if( fRight==0.0 ){
20102010
Th_ErrorMessage(interp, "Divide by 0:", zLeft, nLeft);
20112011
rc = TH_ERROR;
20122012
goto finish;
20132013
}
20142014
Th_SetResultDouble(interp, fLeft/fRight);
20152015
break;
2016
- case OP_ADD: Th_SetResultDouble(interp, fLeft+fRight); break;
2017
- case OP_SUBTRACT: Th_SetResultDouble(interp, fLeft-fRight); break;
2018
- case OP_LT: Th_SetResultInt(interp, fLeft<fRight); break;
2019
- case OP_GT: Th_SetResultInt(interp, fLeft>fRight); break;
2020
- case OP_LE: Th_SetResultInt(interp, fLeft<=fRight); break;
2021
- case OP_GE: Th_SetResultInt(interp, fLeft>=fRight); break;
2022
- case OP_EQ: Th_SetResultInt(interp, fLeft==fRight); break;
2023
- case OP_NE: Th_SetResultInt(interp, fLeft!=fRight); break;
2016
+ case OP_ADD: Th_SetResultDouble(interp, fLeft+fRight); break;
2017
+ case OP_SUBTRACT: Th_SetResultDouble(interp, fLeft-fRight); break;
2018
+ case OP_LT: Th_SetResultInt(interp, fLeft<fRight); break;
2019
+ case OP_GT: Th_SetResultInt(interp, fLeft>fRight); break;
2020
+ case OP_LE: Th_SetResultInt(interp, fLeft<=fRight); break;
2021
+ case OP_GE: Th_SetResultInt(interp, fLeft>=fRight); break;
2022
+ case OP_EQ: Th_SetResultInt(interp, fLeft==fRight); break;
2023
+ case OP_NE: Th_SetResultInt(interp, fLeft!=fRight); break;
2024
+ case OP_UNARY_MINUS: Th_SetResultDouble(interp, -fLeft); break;
2025
+ case OP_UNARY_PLUS: Th_SetResultDouble(interp, +fLeft); break;
20242026
default: assert(!"Internal error");
20252027
}
20262028
}else if( rc==TH_OK ){
20272029
int iEqual = 0;
20282030
assert( eArgType==ARG_STRING );
@@ -2629,13 +2631,13 @@
26292631
if( iVal<0 ){
26302632
isNegative = 1;
26312633
iVal = iVal * -1;
26322634
}
26332635
*(--z) = '\0';
2634
- *(--z) = (char)(48+(iVal%10));
2635
- while( (iVal = (iVal/10))>0 ){
2636
- *(--z) = (char)(48+(iVal%10));
2636
+ *(--z) = (char)(48+((unsigned)iVal%10));
2637
+ while( (iVal = ((unsigned)iVal/10))>0 ){
2638
+ *(--z) = (char)(48+((unsigned)iVal%10));
26372639
assert(z>zBuf);
26382640
}
26392641
if( isNegative ){
26402642
*(--z) = '-';
26412643
}
26422644
--- src/th.c
+++ src/th.c
@@ -2002,27 +2002,29 @@
2002 default: assert(!"Internal error");
2003 }
2004 Th_SetResultInt(interp, iRes);
2005 }else if( rc==TH_OK && eArgType==ARG_NUMBER ){
2006 switch( pExpr->pOp->eOp ) {
2007 case OP_MULTIPLY: Th_SetResultDouble(interp, fLeft*fRight); break;
2008 case OP_DIVIDE:
2009 if( fRight==0.0 ){
2010 Th_ErrorMessage(interp, "Divide by 0:", zLeft, nLeft);
2011 rc = TH_ERROR;
2012 goto finish;
2013 }
2014 Th_SetResultDouble(interp, fLeft/fRight);
2015 break;
2016 case OP_ADD: Th_SetResultDouble(interp, fLeft+fRight); break;
2017 case OP_SUBTRACT: Th_SetResultDouble(interp, fLeft-fRight); break;
2018 case OP_LT: Th_SetResultInt(interp, fLeft<fRight); break;
2019 case OP_GT: Th_SetResultInt(interp, fLeft>fRight); break;
2020 case OP_LE: Th_SetResultInt(interp, fLeft<=fRight); break;
2021 case OP_GE: Th_SetResultInt(interp, fLeft>=fRight); break;
2022 case OP_EQ: Th_SetResultInt(interp, fLeft==fRight); break;
2023 case OP_NE: Th_SetResultInt(interp, fLeft!=fRight); break;
 
 
2024 default: assert(!"Internal error");
2025 }
2026 }else if( rc==TH_OK ){
2027 int iEqual = 0;
2028 assert( eArgType==ARG_STRING );
@@ -2629,13 +2631,13 @@
2629 if( iVal<0 ){
2630 isNegative = 1;
2631 iVal = iVal * -1;
2632 }
2633 *(--z) = '\0';
2634 *(--z) = (char)(48+(iVal%10));
2635 while( (iVal = (iVal/10))>0 ){
2636 *(--z) = (char)(48+(iVal%10));
2637 assert(z>zBuf);
2638 }
2639 if( isNegative ){
2640 *(--z) = '-';
2641 }
2642
--- src/th.c
+++ src/th.c
@@ -2002,27 +2002,29 @@
2002 default: assert(!"Internal error");
2003 }
2004 Th_SetResultInt(interp, iRes);
2005 }else if( rc==TH_OK && eArgType==ARG_NUMBER ){
2006 switch( pExpr->pOp->eOp ) {
2007 case OP_MULTIPLY: Th_SetResultDouble(interp, fLeft*fRight); break;
2008 case OP_DIVIDE:
2009 if( fRight==0.0 ){
2010 Th_ErrorMessage(interp, "Divide by 0:", zLeft, nLeft);
2011 rc = TH_ERROR;
2012 goto finish;
2013 }
2014 Th_SetResultDouble(interp, fLeft/fRight);
2015 break;
2016 case OP_ADD: Th_SetResultDouble(interp, fLeft+fRight); break;
2017 case OP_SUBTRACT: Th_SetResultDouble(interp, fLeft-fRight); break;
2018 case OP_LT: Th_SetResultInt(interp, fLeft<fRight); break;
2019 case OP_GT: Th_SetResultInt(interp, fLeft>fRight); break;
2020 case OP_LE: Th_SetResultInt(interp, fLeft<=fRight); break;
2021 case OP_GE: Th_SetResultInt(interp, fLeft>=fRight); break;
2022 case OP_EQ: Th_SetResultInt(interp, fLeft==fRight); break;
2023 case OP_NE: Th_SetResultInt(interp, fLeft!=fRight); break;
2024 case OP_UNARY_MINUS: Th_SetResultDouble(interp, -fLeft); break;
2025 case OP_UNARY_PLUS: Th_SetResultDouble(interp, +fLeft); break;
2026 default: assert(!"Internal error");
2027 }
2028 }else if( rc==TH_OK ){
2029 int iEqual = 0;
2030 assert( eArgType==ARG_STRING );
@@ -2629,13 +2631,13 @@
2631 if( iVal<0 ){
2632 isNegative = 1;
2633 iVal = iVal * -1;
2634 }
2635 *(--z) = '\0';
2636 *(--z) = (char)(48+((unsigned)iVal%10));
2637 while( (iVal = ((unsigned)iVal/10))>0 ){
2638 *(--z) = (char)(48+((unsigned)iVal%10));
2639 assert(z>zBuf);
2640 }
2641 if( isNegative ){
2642 *(--z) = '-';
2643 }
2644
--- test/th1.test
+++ test/th1.test
@@ -297,5 +297,70 @@
297297
298298
###############################################################################
299299
300300
fossil test-th-eval "string last {AB} {abc}"
301301
test th1-string-last-9 {$RESULT eq {-1}}
302
+
303
+###############################################################################
304
+
305
+fossil test-th-eval "expr -2147483649.0"
306
+test th1-expr-1 {$RESULT eq {-2147483649.0}}
307
+
308
+###############################################################################
309
+
310
+fossil test-th-eval "expr -2147483649"
311
+test th1-expr-2 {$RESULT eq {2147483647}}
312
+
313
+###############################################################################
314
+
315
+fossil test-th-eval "expr -2147483648"
316
+test th1-expr-3 {$RESULT eq {-2147483648}}
317
+
318
+###############################################################################
319
+
320
+fossil test-th-eval "expr -2147483647"
321
+test th1-expr-4 {$RESULT eq {-2147483647}}
322
+
323
+###############################################################################
324
+
325
+fossil test-th-eval "expr -1"
326
+test th1-expr-5 {$RESULT eq {-1}}
327
+
328
+###############################################################################
329
+
330
+fossil test-th-eval "expr 0"
331
+test th1-expr-6 {$RESULT eq {0}}
332
+
333
+###############################################################################
334
+
335
+fossil test-th-eval "expr 0.0"
336
+test th1-expr-7 {$RESULT eq {0.0}}
337
+
338
+###############################################################################
339
+
340
+fossil test-th-eval "expr 1"
341
+test th1-expr-8 {$RESULT eq {1}}
342
+
343
+###############################################################################
344
+
345
+fossil test-th-eval "expr 2147483647"
346
+test th1-expr-9 {$RESULT eq {2147483647}}
347
+
348
+###############################################################################
349
+
350
+fossil test-th-eval "expr 2147483648"
351
+test th1-expr-10 {$RESULT eq {2147483648}}
352
+
353
+###############################################################################
354
+
355
+fossil test-th-eval "expr 2147483649"
356
+test th1-expr-11 {$RESULT eq {2147483649}}
357
+
358
+###############################################################################
359
+
360
+fossil test-th-eval "expr +2147483649"
361
+test th1-expr-12 {$RESULT eq {-2147483647}}
362
+
363
+###############################################################################
364
+
365
+fossil test-th-eval "expr +2147483649.0"
366
+test th1-expr-13 {$RESULT eq {2147483649.0}}
302367
--- test/th1.test
+++ test/th1.test
@@ -297,5 +297,70 @@
297
298 ###############################################################################
299
300 fossil test-th-eval "string last {AB} {abc}"
301 test th1-string-last-9 {$RESULT eq {-1}}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
302
--- test/th1.test
+++ test/th1.test
@@ -297,5 +297,70 @@
297
298 ###############################################################################
299
300 fossil test-th-eval "string last {AB} {abc}"
301 test th1-string-last-9 {$RESULT eq {-1}}
302
303 ###############################################################################
304
305 fossil test-th-eval "expr -2147483649.0"
306 test th1-expr-1 {$RESULT eq {-2147483649.0}}
307
308 ###############################################################################
309
310 fossil test-th-eval "expr -2147483649"
311 test th1-expr-2 {$RESULT eq {2147483647}}
312
313 ###############################################################################
314
315 fossil test-th-eval "expr -2147483648"
316 test th1-expr-3 {$RESULT eq {-2147483648}}
317
318 ###############################################################################
319
320 fossil test-th-eval "expr -2147483647"
321 test th1-expr-4 {$RESULT eq {-2147483647}}
322
323 ###############################################################################
324
325 fossil test-th-eval "expr -1"
326 test th1-expr-5 {$RESULT eq {-1}}
327
328 ###############################################################################
329
330 fossil test-th-eval "expr 0"
331 test th1-expr-6 {$RESULT eq {0}}
332
333 ###############################################################################
334
335 fossil test-th-eval "expr 0.0"
336 test th1-expr-7 {$RESULT eq {0.0}}
337
338 ###############################################################################
339
340 fossil test-th-eval "expr 1"
341 test th1-expr-8 {$RESULT eq {1}}
342
343 ###############################################################################
344
345 fossil test-th-eval "expr 2147483647"
346 test th1-expr-9 {$RESULT eq {2147483647}}
347
348 ###############################################################################
349
350 fossil test-th-eval "expr 2147483648"
351 test th1-expr-10 {$RESULT eq {2147483648}}
352
353 ###############################################################################
354
355 fossil test-th-eval "expr 2147483649"
356 test th1-expr-11 {$RESULT eq {2147483649}}
357
358 ###############################################################################
359
360 fossil test-th-eval "expr +2147483649"
361 test th1-expr-12 {$RESULT eq {-2147483647}}
362
363 ###############################################################################
364
365 fossil test-th-eval "expr +2147483649.0"
366 test th1-expr-13 {$RESULT eq {2147483649.0}}
367

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button