Code Monkey home page Code Monkey logo

Comments (2)

fbarchard avatar fbarchard commented on July 3, 2024

Below is patch to cast string size as int and initialize both values of struct value to 0.

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

from toybox.

enh-google avatar enh-google commented on July 3, 2024

the missing cast was added by 352efdf and the initialization was fixed by 14c91c1.

from toybox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.