comparison lwasm/pseudo.c @ 147:9cf1796259b2

Fixed segfault in fcb,fdb,fqb with empty operands
author lost@l-w.ca
date Thu, 25 Aug 2011 22:29:58 -0600
parents d6e9cc4484f6
children 8967eb907324
comparison
equal deleted inserted replaced
146:f5b8559a5f35 147:9cf1796259b2
127 } 127 }
128 as -> endseen = 1; 128 as -> endseen = 1;
129 } 129 }
130 130
131 PARSEFUNC(pseudo_parse_fcb) 131 PARSEFUNC(pseudo_parse_fcb)
132 {
133 int i = 0;
134 lw_expr_t e;
135
136 for (;;)
137 {
138 e = lwasm_parse_expr(as, p);
139 if (!e)
140 {
141 lwasm_register_error(as, l, "Bad expression (#%s)", i);
142 break;
143 }
144 lwasm_save_expr(l, i++, e);
145 if (**p != ',')
146 break;
147 (*p)++;
148 }
149
150 l -> len = i;
151 }
152
153 EMITFUNC(pseudo_emit_fcb)
154 {
155 int i;
156 lw_expr_t e;
157 // int v;
158
159 for (i = 0; i < l -> len; i++)
160 {
161 e = lwasm_fetch_expr(l, i);
162 lwasm_emitexpr(l, e, 1);
163 }
164 }
165
166 PARSEFUNC(pseudo_parse_fdb)
167 { 132 {
168 int i = 0; 133 int i = 0;
169 lw_expr_t e; 134 lw_expr_t e;
170 135
171 for (;;) 136 for (;;)
180 if (**p != ',') 145 if (**p != ',')
181 break; 146 break;
182 (*p)++; 147 (*p)++;
183 } 148 }
184 149
185 l -> len = i * 2; 150 l -> len = i;
186 } 151 }
187 152
188 EMITFUNC(pseudo_emit_fdb) 153 EMITFUNC(pseudo_emit_fcb)
189 { 154 {
190 int i; 155 int i;
191 lw_expr_t e; 156 lw_expr_t e;
192 // int v; 157 // int v;
193 158
194 for (i = 0; i < (l -> len)/2; i++) 159 for (i = 0; i < l -> len; i++)
195 { 160 {
196 e = lwasm_fetch_expr(l, i); 161 e = lwasm_fetch_expr(l, i);
197 lwasm_emitexpr(l, e, 2); 162 lwasm_emitexpr(l, e, 1);
198 } 163 }
199 } 164 }
200 165
201 PARSEFUNC(pseudo_parse_fqb) 166 PARSEFUNC(pseudo_parse_fdb)
202 { 167 {
203 int i = 0; 168 int i = 0;
204 lw_expr_t e; 169 lw_expr_t e;
205 170
206 for (;;) 171 for (;;)
207 { 172 {
208 e = lwasm_parse_expr(as, p); 173 e = lwasm_parse_expr(as, p);
209 if (!e) 174 if (!e)
210 { 175 {
211 lwasm_register_error(as, l, "Bad expression (#%s)", i); 176 lwasm_register_error(as, l, "Bad expression (#%d)", i);
177 break;
178 }
179 lwasm_save_expr(l, i++, e);
180 if (**p != ',')
181 break;
182 (*p)++;
183 }
184
185 l -> len = i * 2;
186 }
187
188 EMITFUNC(pseudo_emit_fdb)
189 {
190 int i;
191 lw_expr_t e;
192 // int v;
193
194 for (i = 0; i < (l -> len)/2; i++)
195 {
196 e = lwasm_fetch_expr(l, i);
197 lwasm_emitexpr(l, e, 2);
198 }
199 }
200
201 PARSEFUNC(pseudo_parse_fqb)
202 {
203 int i = 0;
204 lw_expr_t e;
205
206 for (;;)
207 {
208 e = lwasm_parse_expr(as, p);
209 if (!e)
210 {
211 lwasm_register_error(as, l, "Bad expression (#%d)", i);
212 break; 212 break;
213 } 213 }
214 lwasm_save_expr(l, i++, e); 214 lwasm_save_expr(l, i++, e);
215 if (**p != ',') 215 if (**p != ',')
216 break; 216 break;