Fossil SCM
Fix a couple corner cases for the TH1 expr command.
Commit
e4e2b2e40e1707764115d250dcfd18ec66a2f6eb
Parent
fe9990adc72f76d…
2 files changed
+14
-12
+65
M
src/th.c
+14
-12
| --- src/th.c | ||
| +++ src/th.c | ||
| @@ -2002,27 +2002,29 @@ | ||
| 2002 | 2002 | default: assert(!"Internal error"); |
| 2003 | 2003 | } |
| 2004 | 2004 | Th_SetResultInt(interp, iRes); |
| 2005 | 2005 | }else if( rc==TH_OK && eArgType==ARG_NUMBER ){ |
| 2006 | 2006 | switch( pExpr->pOp->eOp ) { |
| 2007 | - case OP_MULTIPLY: Th_SetResultDouble(interp, fLeft*fRight); break; | |
| 2007 | + case OP_MULTIPLY: Th_SetResultDouble(interp, fLeft*fRight); break; | |
| 2008 | 2008 | case OP_DIVIDE: |
| 2009 | 2009 | if( fRight==0.0 ){ |
| 2010 | 2010 | Th_ErrorMessage(interp, "Divide by 0:", zLeft, nLeft); |
| 2011 | 2011 | rc = TH_ERROR; |
| 2012 | 2012 | goto finish; |
| 2013 | 2013 | } |
| 2014 | 2014 | Th_SetResultDouble(interp, fLeft/fRight); |
| 2015 | 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; | |
| 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; | |
| 2024 | 2026 | default: assert(!"Internal error"); |
| 2025 | 2027 | } |
| 2026 | 2028 | }else if( rc==TH_OK ){ |
| 2027 | 2029 | int iEqual = 0; |
| 2028 | 2030 | assert( eArgType==ARG_STRING ); |
| @@ -2629,13 +2631,13 @@ | ||
| 2629 | 2631 | if( iVal<0 ){ |
| 2630 | 2632 | isNegative = 1; |
| 2631 | 2633 | iVal = iVal * -1; |
| 2632 | 2634 | } |
| 2633 | 2635 | *(--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)); | |
| 2637 | 2639 | assert(z>zBuf); |
| 2638 | 2640 | } |
| 2639 | 2641 | if( isNegative ){ |
| 2640 | 2642 | *(--z) = '-'; |
| 2641 | 2643 | } |
| 2642 | 2644 |
| --- 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 |
+65
| --- test/th1.test | ||
| +++ test/th1.test | ||
| @@ -297,5 +297,70 @@ | ||
| 297 | 297 | |
| 298 | 298 | ############################################################################### |
| 299 | 299 | |
| 300 | 300 | fossil test-th-eval "string last {AB} {abc}" |
| 301 | 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}} | |
| 302 | 367 |
| --- 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 |