Fossil SCM
More fixes to TH1 integer and expression processing.
Commit
fc248d66aad2c2336e4fddc8a4cca7e9c26c422d
Parent
5fb84d01a221fe2…
2 files changed
+17
-6
+40
M
src/th.c
+17
-6
| --- src/th.c | ||
| +++ src/th.c | ||
| @@ -2227,18 +2227,29 @@ | ||
| 2227 | 2227 | default: { |
| 2228 | 2228 | int j; |
| 2229 | 2229 | const char *zOp; |
| 2230 | 2230 | for(j=0; (zOp=aOperator[j].zOp); j++){ |
| 2231 | 2231 | int nOp = aOperator[j].nOp; |
| 2232 | + int nRemain = nExpr - i; | |
| 2232 | 2233 | int isMatch = 0; |
| 2233 | - if( (nExpr-i)>=nOp && 0==memcmp(zOp, &zExpr[i], nOp) ){ | |
| 2234 | + if( nRemain>=nOp && 0==memcmp(zOp, &zExpr[i], nOp) ){ | |
| 2234 | 2235 | isMatch = 1; |
| 2235 | 2236 | } |
| 2236 | - if( isMatch && aOperator[j].eOp==OP_OPEN_BRACKET ){ | |
| 2237 | - nNest++; | |
| 2238 | - }else if( isMatch && aOperator[j].eOp==OP_CLOSE_BRACKET ){ | |
| 2239 | - nNest--; | |
| 2237 | + if( isMatch ){ | |
| 2238 | + if( aOperator[j].eOp==OP_CLOSE_BRACKET ){ | |
| 2239 | + nNest--; | |
| 2240 | + }else if( nRemain>nOp ){ | |
| 2241 | + if( aOperator[j].eOp==OP_OPEN_BRACKET ){ | |
| 2242 | + nNest++; | |
| 2243 | + } | |
| 2244 | + }else{ | |
| 2245 | + /* | |
| 2246 | + ** This is not really a match because this operator cannot | |
| 2247 | + ** legally appear at the end of the string. | |
| 2248 | + */ | |
| 2249 | + isMatch = 0; | |
| 2250 | + } | |
| 2240 | 2251 | } |
| 2241 | 2252 | if( nToken>0 && aOperator[j].iPrecedence==1 ){ |
| 2242 | 2253 | Expr *pPrev = apToken[nToken-1]; |
| 2243 | 2254 | if( !pPrev->pOp || pPrev->pOp->eOp==OP_CLOSE_BRACKET ){ |
| 2244 | 2255 | continue; |
| @@ -2649,11 +2660,11 @@ | ||
| 2649 | 2660 | } |
| 2650 | 2661 | |
| 2651 | 2662 | if( n>1 && (z[0]=='-' || z[0]=='+') ){ |
| 2652 | 2663 | i = 1; |
| 2653 | 2664 | } |
| 2654 | - if( n>2 && z[i]=='0'){ | |
| 2665 | + if( (n-i)>2 && z[i]=='0' ){ | |
| 2655 | 2666 | if( z[i+1]=='x' || z[i+1]=='X' ){ |
| 2656 | 2667 | i += 2; |
| 2657 | 2668 | base = 16; |
| 2658 | 2669 | isdigit = th_ishexdig; |
| 2659 | 2670 | }else if( z[i+1]=='o' || z[i+1]=='O' ){ |
| 2660 | 2671 |
| --- src/th.c | |
| +++ src/th.c | |
| @@ -2227,18 +2227,29 @@ | |
| 2227 | default: { |
| 2228 | int j; |
| 2229 | const char *zOp; |
| 2230 | for(j=0; (zOp=aOperator[j].zOp); j++){ |
| 2231 | int nOp = aOperator[j].nOp; |
| 2232 | int isMatch = 0; |
| 2233 | if( (nExpr-i)>=nOp && 0==memcmp(zOp, &zExpr[i], nOp) ){ |
| 2234 | isMatch = 1; |
| 2235 | } |
| 2236 | if( isMatch && aOperator[j].eOp==OP_OPEN_BRACKET ){ |
| 2237 | nNest++; |
| 2238 | }else if( isMatch && aOperator[j].eOp==OP_CLOSE_BRACKET ){ |
| 2239 | nNest--; |
| 2240 | } |
| 2241 | if( nToken>0 && aOperator[j].iPrecedence==1 ){ |
| 2242 | Expr *pPrev = apToken[nToken-1]; |
| 2243 | if( !pPrev->pOp || pPrev->pOp->eOp==OP_CLOSE_BRACKET ){ |
| 2244 | continue; |
| @@ -2649,11 +2660,11 @@ | |
| 2649 | } |
| 2650 | |
| 2651 | if( n>1 && (z[0]=='-' || z[0]=='+') ){ |
| 2652 | i = 1; |
| 2653 | } |
| 2654 | if( n>2 && z[i]=='0'){ |
| 2655 | if( z[i+1]=='x' || z[i+1]=='X' ){ |
| 2656 | i += 2; |
| 2657 | base = 16; |
| 2658 | isdigit = th_ishexdig; |
| 2659 | }else if( z[i+1]=='o' || z[i+1]=='O' ){ |
| 2660 |
| --- src/th.c | |
| +++ src/th.c | |
| @@ -2227,18 +2227,29 @@ | |
| 2227 | default: { |
| 2228 | int j; |
| 2229 | const char *zOp; |
| 2230 | for(j=0; (zOp=aOperator[j].zOp); j++){ |
| 2231 | int nOp = aOperator[j].nOp; |
| 2232 | int nRemain = nExpr - i; |
| 2233 | int isMatch = 0; |
| 2234 | if( nRemain>=nOp && 0==memcmp(zOp, &zExpr[i], nOp) ){ |
| 2235 | isMatch = 1; |
| 2236 | } |
| 2237 | if( isMatch ){ |
| 2238 | if( aOperator[j].eOp==OP_CLOSE_BRACKET ){ |
| 2239 | nNest--; |
| 2240 | }else if( nRemain>nOp ){ |
| 2241 | if( aOperator[j].eOp==OP_OPEN_BRACKET ){ |
| 2242 | nNest++; |
| 2243 | } |
| 2244 | }else{ |
| 2245 | /* |
| 2246 | ** This is not really a match because this operator cannot |
| 2247 | ** legally appear at the end of the string. |
| 2248 | */ |
| 2249 | isMatch = 0; |
| 2250 | } |
| 2251 | } |
| 2252 | if( nToken>0 && aOperator[j].iPrecedence==1 ){ |
| 2253 | Expr *pPrev = apToken[nToken-1]; |
| 2254 | if( !pPrev->pOp || pPrev->pOp->eOp==OP_CLOSE_BRACKET ){ |
| 2255 | continue; |
| @@ -2649,11 +2660,11 @@ | |
| 2660 | } |
| 2661 | |
| 2662 | if( n>1 && (z[0]=='-' || z[0]=='+') ){ |
| 2663 | i = 1; |
| 2664 | } |
| 2665 | if( (n-i)>2 && z[i]=='0' ){ |
| 2666 | if( z[i+1]=='x' || z[i+1]=='X' ){ |
| 2667 | i += 2; |
| 2668 | base = 16; |
| 2669 | isdigit = th_ishexdig; |
| 2670 | }else if( z[i+1]=='o' || z[i+1]=='O' ){ |
| 2671 |
+40
| --- test/th1.test | ||
| +++ test/th1.test | ||
| @@ -507,10 +507,50 @@ | ||
| 507 | 507 | |
| 508 | 508 | ############################################################################### |
| 509 | 509 | |
| 510 | 510 | fossil test-th-eval "expr (((1)*2)*2)" |
| 511 | 511 | test th1-expr-41 {$RESULT eq {4}} |
| 512 | + | |
| 513 | +############################################################################### | |
| 514 | + | |
| 515 | +fossil test-th-eval "expr +" | |
| 516 | +test th1-expr-42 {$RESULT eq {TH_ERROR: syntax error in expression: "+"}} | |
| 517 | + | |
| 518 | +############################################################################### | |
| 519 | + | |
| 520 | +fossil test-th-eval "expr -" | |
| 521 | +test th1-expr-43 {$RESULT eq {TH_ERROR: syntax error in expression: "-"}} | |
| 522 | + | |
| 523 | +############################################################################### | |
| 524 | + | |
| 525 | +fossil test-th-eval "expr ++" | |
| 526 | +test th1-expr-44 {$RESULT eq {TH_ERROR: syntax error in expression: "++"}} | |
| 527 | + | |
| 528 | +############################################################################### | |
| 529 | + | |
| 530 | +fossil test-th-eval "expr --" | |
| 531 | +test th1-expr-45 {$RESULT eq {TH_ERROR: syntax error in expression: "--"}} | |
| 532 | + | |
| 533 | +############################################################################### | |
| 534 | + | |
| 535 | +fossil test-th-eval "lindex list +" | |
| 536 | +test th1-expr-46 {$RESULT eq {TH_ERROR: expected integer, got: "+"}} | |
| 537 | + | |
| 538 | +############################################################################### | |
| 539 | + | |
| 540 | +fossil test-th-eval "lindex list -" | |
| 541 | +test th1-expr-47 {$RESULT eq {TH_ERROR: expected integer, got: "-"}} | |
| 542 | + | |
| 543 | +############################################################################### | |
| 544 | + | |
| 545 | +fossil test-th-eval "lindex list +0x" | |
| 546 | +test th1-expr-48 {$RESULT eq {TH_ERROR: expected integer, got: "+0x"}} | |
| 547 | + | |
| 548 | +############################################################################### | |
| 549 | + | |
| 550 | +fossil test-th-eval "lindex list -0x" | |
| 551 | +test th1-expr-49 {$RESULT eq {TH_ERROR: expected integer, got: "-0x"}} | |
| 512 | 552 | |
| 513 | 553 | ############################################################################### |
| 514 | 554 | |
| 515 | 555 | fossil test-th-eval "checkout 1"; # NOTE: Assumes running "in tree". |
| 516 | 556 | test th1-checkout-1 {[string length $RESULT] > 0} |
| 517 | 557 |
| --- test/th1.test | |
| +++ test/th1.test | |
| @@ -507,10 +507,50 @@ | |
| 507 | |
| 508 | ############################################################################### |
| 509 | |
| 510 | fossil test-th-eval "expr (((1)*2)*2)" |
| 511 | test th1-expr-41 {$RESULT eq {4}} |
| 512 | |
| 513 | ############################################################################### |
| 514 | |
| 515 | fossil test-th-eval "checkout 1"; # NOTE: Assumes running "in tree". |
| 516 | test th1-checkout-1 {[string length $RESULT] > 0} |
| 517 |
| --- test/th1.test | |
| +++ test/th1.test | |
| @@ -507,10 +507,50 @@ | |
| 507 | |
| 508 | ############################################################################### |
| 509 | |
| 510 | fossil test-th-eval "expr (((1)*2)*2)" |
| 511 | test th1-expr-41 {$RESULT eq {4}} |
| 512 | |
| 513 | ############################################################################### |
| 514 | |
| 515 | fossil test-th-eval "expr +" |
| 516 | test th1-expr-42 {$RESULT eq {TH_ERROR: syntax error in expression: "+"}} |
| 517 | |
| 518 | ############################################################################### |
| 519 | |
| 520 | fossil test-th-eval "expr -" |
| 521 | test th1-expr-43 {$RESULT eq {TH_ERROR: syntax error in expression: "-"}} |
| 522 | |
| 523 | ############################################################################### |
| 524 | |
| 525 | fossil test-th-eval "expr ++" |
| 526 | test th1-expr-44 {$RESULT eq {TH_ERROR: syntax error in expression: "++"}} |
| 527 | |
| 528 | ############################################################################### |
| 529 | |
| 530 | fossil test-th-eval "expr --" |
| 531 | test th1-expr-45 {$RESULT eq {TH_ERROR: syntax error in expression: "--"}} |
| 532 | |
| 533 | ############################################################################### |
| 534 | |
| 535 | fossil test-th-eval "lindex list +" |
| 536 | test th1-expr-46 {$RESULT eq {TH_ERROR: expected integer, got: "+"}} |
| 537 | |
| 538 | ############################################################################### |
| 539 | |
| 540 | fossil test-th-eval "lindex list -" |
| 541 | test th1-expr-47 {$RESULT eq {TH_ERROR: expected integer, got: "-"}} |
| 542 | |
| 543 | ############################################################################### |
| 544 | |
| 545 | fossil test-th-eval "lindex list +0x" |
| 546 | test th1-expr-48 {$RESULT eq {TH_ERROR: expected integer, got: "+0x"}} |
| 547 | |
| 548 | ############################################################################### |
| 549 | |
| 550 | fossil test-th-eval "lindex list -0x" |
| 551 | test th1-expr-49 {$RESULT eq {TH_ERROR: expected integer, got: "-0x"}} |
| 552 | |
| 553 | ############################################################################### |
| 554 | |
| 555 | fossil test-th-eval "checkout 1"; # NOTE: Assumes running "in tree". |
| 556 | test th1-checkout-1 {[string length $RESULT] > 0} |
| 557 |