comparison lwasm/lwasm.c @ 354:433851a26794

Make base prefix sigils error out if no number following Prefix sigils (0x, %, &, @, $) were parsing to 0 if there was no number following the prefix. Make parsing fail if that is the case. Note that in a couple of obscure cases, it may give "undefined symbol" rather than "bad operand" due to some interactions with other unfortunate features of the source format.
author William Astle <lost@l-w.ca>
date Fri, 15 May 2015 15:47:26 -0600
parents 30b2bad9b5eb
children 433dbc18fb41
comparison
equal deleted inserted replaced
353:e1f4d5af6438 354:433851a26794
437 { 437 {
438 (*p)++; 438 (*p)++;
439 neg = -1; 439 neg = -1;
440 } 440 }
441 441
442 if (!strchr("0123456789", **p)) 442 if (!**p || !strchr("0123456789", **p))
443 return NULL; 443 {
444 (*p)--;
445 if (neg < 0)
446 (*p)--;
447 return NULL;
448 }
444 449
445 while (**p && strchr("0123456789", **p)) 450 while (**p && strchr("0123456789", **p))
446 { 451 {
447 val = val * 10 + (**p - '0'); 452 val = val * 10 + (**p - '0');
448 (*p)++; 453 (*p)++;
461 (*p)++; 466 (*p)++;
462 neg = -1; 467 neg = -1;
463 } 468 }
464 469
465 if (**p != '0' && **p != '1') 470 if (**p != '0' && **p != '1')
466 return NULL; 471 {
472 (*p)--;
473 if (neg < 0)
474 (*p)--;
475 return NULL;
476 }
467 477
468 while (**p && (**p == '0' || **p == '1')) 478 while (**p && (**p == '0' || **p == '1'))
469 { 479 {
470 val = val * 2 + (**p - '0'); 480 val = val * 2 + (**p - '0');
471 (*p)++; 481 (*p)++;
482 { 492 {
483 (*p)++; 493 (*p)++;
484 neg = -1; 494 neg = -1;
485 } 495 }
486 496
487 if (!strchr("0123456789abcdefABCDEF", **p)) 497 if (!**p || !strchr("0123456789abcdefABCDEF", **p))
488 return NULL; 498 {
489 499 (*p)--;
500 if (neg < 0)
501 (*p)--;
502 return NULL;
503 }
490 while (**p && strchr("0123456789abcdefABCDEF", **p)) 504 while (**p && strchr("0123456789abcdefABCDEF", **p))
491 { 505 {
492 v2 = toupper(**p) - '0'; 506 v2 = toupper(**p) - '0';
493 if (v2 > 9) 507 if (v2 > 9)
494 v2 -= 7; 508 v2 -= 7;
502 { 516 {
503 // hexadecimal constant, C style 517 // hexadecimal constant, C style
504 int v = 0, v2; 518 int v = 0, v2;
505 (*p)+=2; 519 (*p)+=2;
506 520
507 if (!strchr("0123456789abcdefABCDEF", **p)) 521 if (!**p || !strchr("0123456789abcdefABCDEF", **p))
508 return NULL; 522 {
509 523 (*p) -= 2;
524 return NULL;
525 }
510 while (**p && strchr("0123456789abcdefABCDEF", **p)) 526 while (**p && strchr("0123456789abcdefABCDEF", **p))
511 { 527 {
512 v2 = toupper(**p) - '0'; 528 v2 = toupper(**p) - '0';
513 if (v2 > 9) 529 if (v2 > 9)
514 v2 -= 7; 530 v2 -= 7;
528 (*p)++; 544 (*p)++;
529 neg = -1; 545 neg = -1;
530 } 546 }
531 547
532 548
533 if (!strchr("01234567", **p)) 549 if (!**p || !strchr("01234567", **p))
534 return NULL; 550 {
535 551 (*p)--;
552 if (neg < 0)
553 (*p)--;
554 return NULL;
555 }
556
536 while (**p && strchr("01234567", **p)) 557 while (**p && strchr("01234567", **p))
537 { 558 {
538 v = v * 8 + (**p - '0'); 559 v = v * 8 + (**p - '0');
539 (*p)++; 560 (*p)++;
540 } 561 }