[Toybox] [PATCH] fix compiler error

enh enh at google.com
Wed Aug 23 09:35:00 PDT 2023


%t is the appropriate choice for pointer differences on both ILP32 and
LP64, and shorter than casting to long:
```
external/toybox/toys/pending/expr.c:209:45: error: format specifies
type 'long' but the argument has type 'int' [-Werror,-Wformat]
  if (!*TT.tok) error_exit("need arg @%ld", TT.tok-toys.optargs);
                                      ~~~   ^~~~~~~~~~~~~~~~~~~
                                      %d
external/toybox/android/device/generated/flags.h:4695:12: note:
expanded from macro 'TT'
#define TT this.expr
           ^
external/toybox/toys/pending/expr.c:217:37: error: format specifies
type 'long' but the argument has type 'int' [-Werror,-Wformat]
      error_exit("Expected ) @%ld", TT.tok-toys.optargs);
                              ~~~   ^~~~~~~~~~~~~~~~~~~
                              %d
external/toybox/android/device/generated/flags.h:4695:12: note:
expanded from macro 'TT'
#define TT this.expr
           ^
2 errors generated.
```

diff --git a/toys/pending/expr.c b/toys/pending/expr.c
index 9868804b..a236aaab 100644
--- a/toys/pending/expr.c
+++ b/toys/pending/expr.c
@@ -206,7 +206,7 @@ static void eval_expr(struct value *ret, int min_prec)
 {
   struct value rhs;

-  if (!*TT.tok) error_exit("need arg @%ld", TT.tok-toys.optargs);
+  if (!*TT.tok) error_exit("need arg @%td", TT.tok-toys.optargs);

   // Everything is infix, so set ret to first value, handling parentheses
   if (!strcmp(*TT.tok, "(")) {
@@ -214,7 +214,7 @@ static void eval_expr(struct value *ret, int min_prec)
     eval_expr(ret, 1);        // We're inside ( ), so min_prec = 1
     if (ret->s && !strcmp(ret->s, ")")) error_exit("empty ( )");
     if (!*TT.tok || strcmp(*TT.tok, ")"))
-      error_exit("Expected ) @%ld", TT.tok-toys.optargs);
+      error_exit("Expected ) @%td", TT.tok-toys.optargs);
   } else ret->s = *TT.tok;  // simple literal, all values start as strings
   TT.tok++;


More information about the Toybox mailing list