[v2,09/65] bpf: use is_whitespace()

Message ID 05db5eb8-6467-4d91-bd9a-0315859ae494@suse.com
State New
Headers
Series gas: whitespace handling |

Commit Message

Jan Beulich Jan. 27, 2025, 4:08 p.m. UTC
  Wherever blanks are permissible in input, tabs ought to be permissible,
too. This is particularly relevant when -f is passed to gas (alongside
appropriate input). At the same time use is_end_of_stmt() instead of
open-coded nul char checks.
---
v2: New.
  

Comments

Alan Modra Jan. 28, 2025, 9:21 a.m. UTC | #1
On Mon, Jan 27, 2025 at 05:08:18PM +0100, Jan Beulich wrote:
> Wherever blanks are permissible in input, tabs ought to be permissible,
> too. This is particularly relevant when -f is passed to gas (alongside
> appropriate input). At the same time use is_end_of_stmt() instead of
> open-coded nul char checks.
> ---
> v2: New.
> 
> --- a/gas/config/tc-bpf.c
> +++ b/gas/config/tc-bpf.c
> @@ -1274,7 +1274,7 @@ parse_expression (char *s, expressionS *
>       these whitespaces.  */
>    {
>      char *p;
> -    for (p = s - 1; p >= saved_s && *p == ' '; --p)
> +    for (p = s - 1; p >= saved_s && is_whitespace (*p); --p)
>        --s;
>    }
>  
> @@ -1501,7 +1501,7 @@ md_assemble (char *str ATTRIBUTE_UNUSED)
>            if (*p == ' ')
>              {
>                /* Expect zero or more spaces.  */
> -              while (*s != '\0' && (*s == ' ' || *s == '\t'))
> +              while (!is_end_of_stmt (*s) && is_whitespace (*s))

Just is_whitespace here.

>                  s += 1;
>                p += 1;
>              }
> @@ -1520,20 +1520,20 @@ md_assemble (char *str ATTRIBUTE_UNUSED)
>                else if (*(p + 1) == 'w')
>                  {
>                    /* Expect zero or more spaces.  */
> -                  while (*s != '\0' && (*s == ' ' || *s == '\t'))
> +                  while (!is_end_of_stmt (*s) && is_whitespace (*s))

Same.

>                      s += 1;
>                    p += 2;
>                  }
>                else if (*(p + 1) == 'W')
>                  {
>                    /* Expect one or more spaces.  */
> -                  if (*s != ' ' && *s != '\t')
> +                  if (!is_whitespace (*s))
>                      {
>                        PARSE_ERROR ("expected white space, got '%s'",
>                                     s);
>                        break;
>                      }
> -                  while (*s != '\0' && (*s == ' ' || *s == '\t'))
> +                  while (!is_end_of_stmt (*s) && is_whitespace (*s))

Same.

>                      s += 1;
>                    p += 2;
>                  }
> @@ -1620,7 +1620,7 @@ md_assemble (char *str ATTRIBUTE_UNUSED)
>  
>                    if (p[1] == 'I')
>                      {
> -                      while (*s == ' ' || *s == '\t')
> +                      while (is_whitespace (*s))
>                          s += 1;
>                        if (*s != '+' && *s != '-')
>                          {
> @@ -1643,7 +1643,7 @@ md_assemble (char *str ATTRIBUTE_UNUSED)
>                  {
>                    char *exp = NULL;
>  
> -                  while (*s == ' ' || *s == '\t')
> +                  while (is_whitespace (*s))
>                      s += 1;
>                    if (*s != '+' && *s != '-')
>                      {
> @@ -1735,9 +1735,9 @@ md_assemble (char *str ATTRIBUTE_UNUSED)
>        if (*p == '\0')
>          {
>            /* Allow white spaces at the end of the line.  */
> -          while (*s != '\0' && (*s == ' ' || *s == '\t'))
> +          while (!is_end_of_stmt (*s) && is_whitespace (*s))

Again.

>              s += 1;
> -          if (*s == '\0')
> +          if (is_end_of_stmt (*s))
>              /* We parsed an instruction successfully.  */
>              break;
>            PARSE_ERROR ("extra junk at end of line");
  
Jan Beulich Jan. 28, 2025, 10:31 a.m. UTC | #2
On 28.01.2025 10:21, Alan Modra wrote:
> On Mon, Jan 27, 2025 at 05:08:18PM +0100, Jan Beulich wrote:
>> Wherever blanks are permissible in input, tabs ought to be permissible,
>> too. This is particularly relevant when -f is passed to gas (alongside
>> appropriate input). At the same time use is_end_of_stmt() instead of
>> open-coded nul char checks.
>> ---
>> v2: New.
>>
>> --- a/gas/config/tc-bpf.c
>> +++ b/gas/config/tc-bpf.c
>> @@ -1274,7 +1274,7 @@ parse_expression (char *s, expressionS *
>>       these whitespaces.  */
>>    {
>>      char *p;
>> -    for (p = s - 1; p >= saved_s && *p == ' '; --p)
>> +    for (p = s - 1; p >= saved_s && is_whitespace (*p); --p)
>>        --s;
>>    }
>>  
>> @@ -1501,7 +1501,7 @@ md_assemble (char *str ATTRIBUTE_UNUSED)
>>            if (*p == ' ')
>>              {
>>                /* Expect zero or more spaces.  */
>> -              while (*s != '\0' && (*s == ' ' || *s == '\t'))
>> +              while (!is_end_of_stmt (*s) && is_whitespace (*s))
> 
> Just is_whitespace here.

Oh, yes. In later patches I did that, but then forgot to check back in
earlier ones. Thanks for noticing.

Jan
  

Patch

--- a/gas/config/tc-bpf.c
+++ b/gas/config/tc-bpf.c
@@ -1274,7 +1274,7 @@  parse_expression (char *s, expressionS *
      these whitespaces.  */
   {
     char *p;
-    for (p = s - 1; p >= saved_s && *p == ' '; --p)
+    for (p = s - 1; p >= saved_s && is_whitespace (*p); --p)
       --s;
   }
 
@@ -1501,7 +1501,7 @@  md_assemble (char *str ATTRIBUTE_UNUSED)
           if (*p == ' ')
             {
               /* Expect zero or more spaces.  */
-              while (*s != '\0' && (*s == ' ' || *s == '\t'))
+              while (!is_end_of_stmt (*s) && is_whitespace (*s))
                 s += 1;
               p += 1;
             }
@@ -1520,20 +1520,20 @@  md_assemble (char *str ATTRIBUTE_UNUSED)
               else if (*(p + 1) == 'w')
                 {
                   /* Expect zero or more spaces.  */
-                  while (*s != '\0' && (*s == ' ' || *s == '\t'))
+                  while (!is_end_of_stmt (*s) && is_whitespace (*s))
                     s += 1;
                   p += 2;
                 }
               else if (*(p + 1) == 'W')
                 {
                   /* Expect one or more spaces.  */
-                  if (*s != ' ' && *s != '\t')
+                  if (!is_whitespace (*s))
                     {
                       PARSE_ERROR ("expected white space, got '%s'",
                                    s);
                       break;
                     }
-                  while (*s != '\0' && (*s == ' ' || *s == '\t'))
+                  while (!is_end_of_stmt (*s) && is_whitespace (*s))
                     s += 1;
                   p += 2;
                 }
@@ -1620,7 +1620,7 @@  md_assemble (char *str ATTRIBUTE_UNUSED)
 
                   if (p[1] == 'I')
                     {
-                      while (*s == ' ' || *s == '\t')
+                      while (is_whitespace (*s))
                         s += 1;
                       if (*s != '+' && *s != '-')
                         {
@@ -1643,7 +1643,7 @@  md_assemble (char *str ATTRIBUTE_UNUSED)
                 {
                   char *exp = NULL;
 
-                  while (*s == ' ' || *s == '\t')
+                  while (is_whitespace (*s))
                     s += 1;
                   if (*s != '+' && *s != '-')
                     {
@@ -1735,9 +1735,9 @@  md_assemble (char *str ATTRIBUTE_UNUSED)
       if (*p == '\0')
         {
           /* Allow white spaces at the end of the line.  */
-          while (*s != '\0' && (*s == ' ' || *s == '\t'))
+          while (!is_end_of_stmt (*s) && is_whitespace (*s))
             s += 1;
-          if (*s == '\0')
+          if (is_end_of_stmt (*s))
             /* We parsed an instruction successfully.  */
             break;
           PARSE_ERROR ("extra junk at end of line");