There are 2 warnings in expr.c which occur during android builds:

external/toybox/toys/pending/expr.c:116:28: warning: field precision should
have type 'int', but argument has type 'long' [-Wformat]
      ret->s = xmprintf("%.*s", m[1].rm_eo-m[1].rm_so, target+m[1].rm_so);
                         ~~^~   ~~~~~~~~~~~~~~~~~~~~~
external/toybox/toys/pending/expr.c:247:24: warning: missing field 'i'
initializer [-Wmissing-field-initializers]
  struct value ret = {0};
                       ^

I proposed a patch there, but they suggested doing the fix here first.

Filed issue here:
https://github.com/landley/toybox/issues/64

Attached is the git format-patch -1 patch
From 0ca5c2fe2999e8305bb3077b2c1c1b57ae66bdb2 Mon Sep 17 00:00:00 2001
From: Frank Barchard <fbarch...@google.com>
Date: Mon, 10 Apr 2017 10:37:22 -0700
Subject: [PATCH] toybox expr fixes for warnings

string size delimiter expects int, so cast parameter from long to int.
initializer for struct expects 2 values, so pass 0 for pointer and
0LL for long long.

Bug: 37207025
Test: local build is has no warnings in expr
Change-Id: If2fc7fe831afa860798f83049aae376aba59c594
---
 toys/pending/expr.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/toys/pending/expr.c b/toys/pending/expr.c
index 743a953..2aacd08 100644
--- a/toys/pending/expr.c
+++ b/toys/pending/expr.c
@@ -113,7 +113,8 @@ static void re(char *target, char *pattern, struct value *ret)
   if (!regexec(&pat, target, 2, m, 0) && !m[0].rm_so) {
     // Return first parenthesized subexpression as string, or length of match
     if (pat.re_nsub>0) {
-      ret->s = xmprintf("%.*s", m[1].rm_eo-m[1].rm_so, target+m[1].rm_so);
+      ret->s = xmprintf("%.*s", (int)(m[1].rm_eo-m[1].rm_so),
+          target+m[1].rm_so);
       if (TT.refree) free(TT.refree);
       TT.refree = ret->s;
     } else assign_int(ret, m[0].rm_eo);
@@ -141,7 +142,7 @@ static struct op_def {
   // comparison ops, precedence 3, signature SI_TO_I
   {"=", 3, SI_TO_I, EQ }, {"==", 3, SI_TO_I, EQ  }, {"!=", 3, SI_TO_I, NE },
   {">", 3, SI_TO_I, GT }, {">=", 3, SI_TO_I, GTE },
-  {"<", 3, SI_TO_I, LT }, {"<=", 3, SI_TO_I, LTE }, 
+  {"<", 3, SI_TO_I, LT }, {"<=", 3, SI_TO_I, LTE },
   // arithmetic ops, precedence 4 and 5, signature I_TO_I
   {"+", 4, I_TO_I, ADD }, {"-",  4, I_TO_I, SUB },
   {"*", 5, I_TO_I, MUL }, {"/",  5, I_TO_I, DIVI }, {"%", 5, I_TO_I, MOD },
@@ -163,7 +164,7 @@ void eval_op(struct op_def *o, struct value *ret, struct value *rhs)
     case OR:  if (is_false(ret)) *ret = *rhs; break;
     case AND: if (is_false(ret) || is_false(rhs)) assign_int(ret, 0); break;
     }
-    break;  
+    break;
 
   case SI_TO_I:
     if (get_int(ret, &a) && get_int(rhs, &b)) { // both are ints
@@ -244,7 +245,7 @@ static void eval_expr(struct value *ret, int min_prec)
 
 void expr_main(void)
 {
-  struct value ret = {0};
+  struct value ret = {0, 0LL};
 
   toys.exitval = 2; // if exiting early, indicate error
   TT.tok = toys.optargs; // initialize global token
-- 
2.12.2.715.g7642488e1d-goog

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to