2222#include "listing.h"
2323#include "labels.h"
2424#include "iflag.h"
25+ #include "quote.h"
2526
2627struct cpunames {
2728 const char * name ;
@@ -178,34 +179,51 @@ static int get_bits(const char *value)
178179
179180static enum directive parse_directive_line (char * * directive , char * * value )
180181{
181- char * p , * q , * buf ;
182+ char * p , * q , * eol , * buf ;
183+ char c ;
182184
183185 buf = nasm_skip_spaces (* directive );
184186
185187 /*
186188 * It should be enclosed in [ ].
187- * XXX: we don't check there is nothing else on the remainder of the
188- * line, except a possible comment.
189+ *
190+ * Strip off the comments. We should really strip the comments in
191+ * generic code, not here. While we're at it, it would be better
192+ * to pass the backend a series of tokens instead of a raw string,
193+ * and actually process quoted strings for it, like of like argv
194+ * is handled in C.
189195 */
190196 if (* buf != '[' )
191197 return D_none ;
192- q = strchr (buf , ']' );
193- if (!q )
194- return D_corrupt ;
198+
199+ q = buf ;
200+ while ((c = * q ) != ']' ) {
201+ switch (c ) {
202+ case '\0' :
203+ case ';' :
204+ return D_corrupt ; /* No ] in directive */
205+ case '\'' :
206+ case '\"' :
207+ case '`' :
208+ q = nasm_skip_string (q );
209+ if (!* q ++ )
210+ return D_corrupt ;
211+ break ;
212+ default :
213+ q ++ ;
214+ break ;
215+ }
216+ }
195217
196218 /*
197- * Strip off the comments. XXX: this doesn't account for quoted
198- * strings inside a directive. We should really strip the
199- * comments in generic code, not here. While we're at it, it
200- * would be better to pass the backend a series of tokens instead
201- * of a raw string, and actually process quoted strings for it,
202- * like of like argv is handled in C.
219+ * Found the ] at the end of the directive. Make sure there isn't
220+ * anything else at the end of the line, except a possible
221+ * comment.
203222 */
204- p = strchr (buf , ';' );
205- if (p ) {
206- if (p < q ) /* ouch! somewhere inside */
207- return D_corrupt ;
208- * p = '\0' ;
223+ eol = nasm_skip_spaces (q + 1 );
224+ if (* eol != '\0' && * eol != ';' ) {
225+ nasm_warn (WARN_DIRECTIVE_GARBAGE_EOL ,
226+ "garbage found on line after directive" );
209227 }
210228
211229 /* no brace, no trailing spaces */
@@ -264,7 +282,7 @@ bool process_directives(char *directive)
264282
265283 switch (d ) {
266284 case D_none :
267- return D_none ; /* Not a directive */
285+ return false;
268286
269287 case D_corrupt :
270288 nasm_nonfatal ("invalid directive line" );
@@ -285,6 +303,12 @@ bool process_directives(char *directive)
285303 default :
286304 panic ();
287305 }
306+ } else if (d < D_pseudo_ops ) {
307+ nasm_nonfatal ("internal error: unimplemented directive [%s]" ,
308+ directive );
309+ break ;
310+ } else {
311+ goto unknown ;
288312 }
289313 break ;
290314
@@ -617,11 +641,10 @@ bool process_directives(char *directive)
617641 break ;
618642 }
619643
620-
621644 /* A common error message */
622645 if (bad_param ) {
623646 nasm_nonfatal ("invalid parameter to [%s] directive" , directive );
624647 }
625648
626- return d != D_none ;
649+ return true ;
627650}
0 commit comments