Przeglądaj źródła

core: cast operator (int) converts hex strings as well

- in addition to dec string
Daniel-Constantin Mierla 10 lat temu
rodzic
commit
33f1591211
1 zmienionych plików z 9 dodań i 5 usunięć
  1. 9 5
      rvalue.c

+ 9 - 5
rvalue.c

@@ -997,16 +997,20 @@ rv_str:
 	/* if "" => 0 (most likely case) */
 	if (likely(s->len==0)) *i=0;
 	else if (unlikely(str2sint(s, i)!=0)){
-		/* error converting to int => non numeric => 0 */
-		*i=0;
+		/* dec to int failed, try hex to int */
+		if(!(s->len>2 && s->s[0]=='0' && (s->s[1]=='x' || s->s[1]=='X')
+					&& (hexstr2int(s->s+2, s->len-2, (unsigned int*)i)==0))) {
+			/* error converting to int => non numeric => 0 */
+			*i=0;
 #ifdef RV_STR2INT_VERBOSE_ERR
-		WARN("automatic string to int conversion for \"%.*s\" failed\n",
+			WARN("automatic string to int conversion for \"%.*s\" failed\n",
 				s->len, ZSW(s->s));
-		/* return an error code */
+			/* return an error code */
 #endif
 #ifdef RV_STR2INT_ERR
-		ret=-1;
+			ret=-1;
 #endif
+		}
 	}
 	if (destroy_pval)
 		pv_value_destroy(&pval);