comparison lwasm/pseudo.c @ 159:8967eb907324

Trap negative sizes for [rz]m[bdq] and flag error
author lost@l-w.ca
date Sun, 28 Aug 2011 14:16:45 -0600
parents 9cf1796259b2
children 5965c01b3dec
comparison
equal deleted inserted replaced
158:8dead67ba607 159:8967eb907324
525 525
526 expr = lwasm_fetch_expr(l, 0); 526 expr = lwasm_fetch_expr(l, 0);
527 527
528 if (lw_expr_istype(expr, lw_expr_type_int)) 528 if (lw_expr_istype(expr, lw_expr_type_int))
529 { 529 {
530 if (lw_expr_intval(expr) < 0)
531 {
532 lwasm_register_error(as, l, "Negative reservation sizes make no sense!");
533 l -> len = 0;
534 l -> dlen = 0;
535 return;
536 }
530 if (l -> inmod) 537 if (l -> inmod)
531 l -> dlen = lw_expr_intval(expr); 538 l -> dlen = lw_expr_intval(expr);
532 else 539 else
533 l -> len = lw_expr_intval(expr); 540 l -> len = lw_expr_intval(expr);
534 } 541 }
538 { 545 {
539 if (l -> lint) 546 if (l -> lint)
540 return; 547 return;
541 548
542 if (l -> len < 0 || l -> dlen < 0) 549 if (l -> len < 0 || l -> dlen < 0)
543 lwasm_register_error(as, l, "Expression not constant"); 550 lwasm_register_error(as, l, "Expression not constant: %d %d", l -> len, l -> dlen);
544 } 551 }
545 552
546 PARSEFUNC(pseudo_parse_rmd) 553 PARSEFUNC(pseudo_parse_rmd)
547 { 554 {
548 lw_expr_t expr; 555 lw_expr_t expr;
602 609
603 expr = lwasm_fetch_expr(l, 0); 610 expr = lwasm_fetch_expr(l, 0);
604 611
605 if (lw_expr_istype(expr, lw_expr_type_int)) 612 if (lw_expr_istype(expr, lw_expr_type_int))
606 { 613 {
614 if (lw_expr_intval(expr) < 0)
615 {
616 lwasm_register_error(as, l, "Negative reservation sizes make no sense!");
617 l -> len = 0;
618 l -> dlen = 0;
619 return;
620 }
607 if (l -> inmod) 621 if (l -> inmod)
608 l -> dlen = lw_expr_intval(expr) * 2; 622 l -> dlen = lw_expr_intval(expr) * 2;
609 else 623 else
610 l -> len = lw_expr_intval(expr) * 2; 624 l -> len = lw_expr_intval(expr) * 2;
611 } 625 }
679 693
680 expr = lwasm_fetch_expr(l, 0); 694 expr = lwasm_fetch_expr(l, 0);
681 695
682 if (lw_expr_istype(expr, lw_expr_type_int)) 696 if (lw_expr_istype(expr, lw_expr_type_int))
683 { 697 {
698 if (lw_expr_intval(expr) < 0)
699 {
700 lwasm_register_error(as, l, "Negative reservation sizes make no sense!");
701 l -> len = 0;
702 l -> dlen = 0;
703 return;
704 }
684 if (l -> inmod) 705 if (l -> inmod)
685 l -> dlen = lw_expr_intval(expr) * 4; 706 l -> dlen = lw_expr_intval(expr) * 4;
686 else 707 else
687 l -> len = lw_expr_intval(expr) * 4; 708 l -> len = lw_expr_intval(expr) * 4;
688 } 709 }
720 741
721 expr = lwasm_fetch_expr(l, 0); 742 expr = lwasm_fetch_expr(l, 0);
722 743
723 if (lw_expr_istype(expr, lw_expr_type_int)) 744 if (lw_expr_istype(expr, lw_expr_type_int))
724 { 745 {
746 if (lw_expr_intval(expr) < 0)
747 {
748 lwasm_register_error(as, l, "Negative block sizes make no sense!");
749 l -> len = 0;
750 return;
751 }
725 l -> len = lw_expr_intval(expr) * 4; 752 l -> len = lw_expr_intval(expr) * 4;
726 } 753 }
727 } 754 }
728 755
729 EMITFUNC(pseudo_emit_zmq) 756 EMITFUNC(pseudo_emit_zmq)
763 790
764 expr = lwasm_fetch_expr(l, 0); 791 expr = lwasm_fetch_expr(l, 0);
765 792
766 if (lw_expr_istype(expr, lw_expr_type_int)) 793 if (lw_expr_istype(expr, lw_expr_type_int))
767 { 794 {
795 if (lw_expr_intval(expr) < 0)
796 {
797 lwasm_register_error(as, l, "Negative block sizes make no sense!");
798 l -> len = 0;
799 return;
800 }
768 l -> len = lw_expr_intval(expr) * 2; 801 l -> len = lw_expr_intval(expr) * 2;
769 } 802 }
770 } 803 }
771 804
772 EMITFUNC(pseudo_emit_zmd) 805 EMITFUNC(pseudo_emit_zmd)
805 838
806 expr = lwasm_fetch_expr(l, 0); 839 expr = lwasm_fetch_expr(l, 0);
807 840
808 if (lw_expr_istype(expr, lw_expr_type_int)) 841 if (lw_expr_istype(expr, lw_expr_type_int))
809 { 842 {
843 if (lw_expr_intval(expr) < 0)
844 {
845 lwasm_register_error(as, l, "Negative block sizes make no sense!");
846 l -> len = 0;
847 return;
848 }
810 l -> len = lw_expr_intval(expr); 849 l -> len = lw_expr_intval(expr);
811 } 850 }
812 } 851 }
813 852
814 EMITFUNC(pseudo_emit_zmb) 853 EMITFUNC(pseudo_emit_zmb)