@@ -532,7 +532,7 @@ int main(int argc, char **argv)
532532 if (trimed == NULL || trimed [0 ] == '\n' || trimed [0 ] == '\r' || trimed [0 ] == '\0' || trimed [0 ] == ' ' )
533533 {
534534 /* If not, warn the user. And quit. */
535- fprintf (stderr , "Line %llu: Both a size and a value must be declared for a .data element.\n" , FILELINE );
535+ fprintf (stderr , "Line %llu: Both a size must be declared for a .data element.\n" , FILELINE );
536536 exit (7 );
537537 }
538538 /* Errno can be set non-zero for many reasons. Set it to zero now so we can check the result of strtoul. */
@@ -543,36 +543,33 @@ int main(int argc, char **argv)
543543 if (errno != 0 || trimed == endptr )
544544 {
545545 /* If either is true, warn the user and quit. */
546- fprintf (stderr , "Line %llu: Both a size and a value must be declared for a .data element or an invalid value was used.\n" , FILELINE );
546+ fprintf (stderr , "Line %llu: Both a size must be declared for a .data element or an invalid value was used.\n" , FILELINE );
547547 exit (7 );
548548 }
549549 free (trimed );
550550 /* Get the next token (which should be the initial value of the .data element). */
551551 tokens = strtok (NULL , delims );
552552 trimed = trim (tokens );
553- /* Check that the token is valid. */
554- if (trimed == NULL || trimed [0 ] == '\n' || trimed [0 ] == '\r' || trimed [0 ] == '\0' || trimed [0 ] == ' ' )
555- {
556- /* If not, warn the user. And quit. */
557- fprintf (stderr , "Line %llu: Both a size and a value must be declared for a .data element.\n" , FILELINE );
558- exit (7 );
559- }
560- /* Errno can be set non-zero for many reasons. Set it to zero now so we can check the result of strtoul. */
561- errno = 0 ;
562- /* Try to get the initial value of the data element */
563- datavalue = estrtol (trimed , & endptr , STDHEX );
564- /* If tokens == endptr, this isn't a number, so it should be a label. */
565- if (errno != 0 || trimed == endptr )
553+ /* Check that the token is valid. If not, assume non-initalisation */
554+ if (trimed != NULL && trimed [0 ] != '\n' && trimed [0 ] != '\r' && trimed [0 ] != '\0' && trimed [0 ] != ' ' )
566555 {
567- /* However, if the storage size isn't 4, the programmer isn't using this correctly. */
568- if (datasize != 4 )
556+ /* Errno can be set non-zero for many reasons. Set it to zero now so we can check the result of strtoul. */
557+ errno = 0 ;
558+ /* Try to get the initial value of the data element */
559+ datavalue = estrtol (trimed , & endptr , STDHEX );
560+ /* If tokens == endptr, this isn't a number, so it should be a label. */
561+ if (errno != 0 || trimed == endptr )
569562 {
570- /* Complain and die. */
571- fprintf (stderr , "Line %llu: When a .data declaration is used with a label, the storage size must be 4.\n" , FILELINE );
572- exit (31 );
563+ /* However, if the storage size isn't 4, the programmer isn't using this correctly. */
564+ if (datasize != 4 )
565+ {
566+ /* Complain and die. */
567+ fprintf (stderr , "Line %llu: When a .data declaration is used with a label, the storage size must be 4.\n" , FILELINE );
568+ exit (31 );
569+ }
570+ /* Otherwise, try and get the address of that label. */
571+ datavalue = findlabel (& unknownlabels , & labels , trimed , numlabels , & numunknownlabels , bits , LABEL );
573572 }
574- /* Otherwise, try and get the address of that label. */
575- datavalue = findlabel (& unknownlabels , & labels , trimed , numlabels , & numunknownlabels , bits , LABEL );
576573 }
577574 free (trimed );
578575 /* Get the next token as this will probably be a newline, and this speeds up the reading process for the next line. */
0 commit comments