Browse code

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

- in addition to dec string

Daniel-Constantin Mierla authored on 16/09/2015 21:54:02
Showing 1 changed files
... ...
@@ -997,16 +997,20 @@ rv_str:
997 997
 	/* if "" => 0 (most likely case) */
998 998
 	if (likely(s->len==0)) *i=0;
999 999
 	else if (unlikely(str2sint(s, i)!=0)){
1000
-		/* error converting to int => non numeric => 0 */
1001
-		*i=0;
1000
+		/* dec to int failed, try hex to int */
1001
+		if(!(s->len>2 && s->s[0]=='0' && (s->s[1]=='x' || s->s[1]=='X')
1002
+					&& (hexstr2int(s->s+2, s->len-2, (unsigned int*)i)==0))) {
1003
+			/* error converting to int => non numeric => 0 */
1004
+			*i=0;
1002 1005
 #ifdef RV_STR2INT_VERBOSE_ERR
1003
-		WARN("automatic string to int conversion for \"%.*s\" failed\n",
1006
+			WARN("automatic string to int conversion for \"%.*s\" failed\n",
1004 1007
 				s->len, ZSW(s->s));
1005
-		/* return an error code */
1008
+			/* return an error code */
1006 1009
 #endif
1007 1010
 #ifdef RV_STR2INT_ERR
1008
-		ret=-1;
1011
+			ret=-1;
1009 1012
 #endif
1013
+		}
1010 1014
 	}
1011 1015
 	if (destroy_pval)
1012 1016
 		pv_value_destroy(&pval);