[GitHub] [mynewt-core] utzig commented on a change in pull request #2180: sys/config: Support for unsigned integer types

2020-02-12 Thread GitBox
utzig commented on a change in pull request #2180: sys/config: Support for 
unsigned integer types
URL: https://github.com/apache/mynewt-core/pull/2180#discussion_r378438008
 
 

 ##
 File path: sys/config/src/config.c
 ##
 @@ -194,6 +196,34 @@ conf_value_from_str(char *val_str, enum conf_type type, 
void *vp, int maxlen)
 }
 *(int64_t *)vp = val64;
 break;
+case CONF_UINT8:
+case CONF_UINT16:
+case CONF_UINT32:
+uval = strtoul(val_str, , 0);
+if (*eptr != '\0') {
+goto err;
+}
+if (type == CONF_UINT8) {
+if (uval > UINT8_MAX) {
+goto err;
+}
+*(uint8_t *)vp = uval;
+} else if (type == CONF_UINT16) {
+if (uval > UINT16_MAX) {
+goto err;
+}
+*(uint16_t *)vp = uval;
+} else if (type == CONF_UINT32) {
+*(uint32_t *)vp = uval;
+}
+break;
+case CONF_UINT64:
+uval64 = strtoull(val_str, , 0);
 
 Review comment:
   > Would you mind taking a look at the latest commits?
   
   Just did, looks good!


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [mynewt-core] utzig commented on a change in pull request #2180: sys/config: Support for unsigned integer types

2020-02-12 Thread GitBox
utzig commented on a change in pull request #2180: sys/config: Support for 
unsigned integer types
URL: https://github.com/apache/mynewt-core/pull/2180#discussion_r378424887
 
 

 ##
 File path: sys/config/src/config.c
 ##
 @@ -194,6 +196,34 @@ conf_value_from_str(char *val_str, enum conf_type type, 
void *vp, int maxlen)
 }
 *(int64_t *)vp = val64;
 break;
+case CONF_UINT8:
+case CONF_UINT16:
+case CONF_UINT32:
+uval = strtoul(val_str, , 0);
+if (*eptr != '\0') {
+goto err;
+}
+if (type == CONF_UINT8) {
+if (uval > UINT8_MAX) {
+goto err;
+}
+*(uint8_t *)vp = uval;
+} else if (type == CONF_UINT16) {
+if (uval > UINT16_MAX) {
+goto err;
+}
+*(uint16_t *)vp = uval;
+} else if (type == CONF_UINT32) {
+*(uint32_t *)vp = uval;
+}
+break;
+case CONF_UINT64:
+uval64 = strtoull(val_str, , 0);
 
 Review comment:
   It looks like both `strtoul` and `strtoull` are mapped to `strntoumax` 
inside baselibc, just using a different cast!


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [mynewt-core] utzig commented on a change in pull request #2180: sys/config: Support for unsigned integer types

2020-02-12 Thread GitBox
utzig commented on a change in pull request #2180: sys/config: Support for 
unsigned integer types
URL: https://github.com/apache/mynewt-core/pull/2180#discussion_r378321583
 
 

 ##
 File path: sys/config/src/config.c
 ##
 @@ -194,6 +196,34 @@ conf_value_from_str(char *val_str, enum conf_type type, 
void *vp, int maxlen)
 }
 *(int64_t *)vp = val64;
 break;
+case CONF_UINT8:
+case CONF_UINT16:
+case CONF_UINT32:
+uval = strtoul(val_str, , 0);
+if (*eptr != '\0') {
+goto err;
+}
+if (type == CONF_UINT8) {
+if (uval > UINT8_MAX) {
+goto err;
+}
+*(uint8_t *)vp = uval;
+} else if (type == CONF_UINT16) {
+if (uval > UINT16_MAX) {
+goto err;
+}
+*(uint16_t *)vp = uval;
+} else if (type == CONF_UINT32) {
 
 Review comment:
   Since this is inside a `case` I don't think `type` could anything but 
`CONF_UINT32`here!


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [mynewt-core] utzig commented on a change in pull request #2180: sys/config: Support for unsigned integer types

2020-02-12 Thread GitBox
utzig commented on a change in pull request #2180: sys/config: Support for 
unsigned integer types
URL: https://github.com/apache/mynewt-core/pull/2180#discussion_r378322864
 
 

 ##
 File path: sys/config/src/config.c
 ##
 @@ -194,6 +196,34 @@ conf_value_from_str(char *val_str, enum conf_type type, 
void *vp, int maxlen)
 }
 *(int64_t *)vp = val64;
 break;
+case CONF_UINT8:
+case CONF_UINT16:
+case CONF_UINT32:
+uval = strtoul(val_str, , 0);
+if (*eptr != '\0') {
+goto err;
+}
+if (type == CONF_UINT8) {
+if (uval > UINT8_MAX) {
+goto err;
+}
+*(uint8_t *)vp = uval;
+} else if (type == CONF_UINT16) {
+if (uval > UINT16_MAX) {
+goto err;
+}
+*(uint16_t *)vp = uval;
+} else if (type == CONF_UINT32) {
+*(uint32_t *)vp = uval;
+}
+break;
+case CONF_UINT64:
+uval64 = strtoull(val_str, , 0);
 
 Review comment:
   I see there's special handling for `UINT64` here and also for `INT64` above, 
but I am not sure why you can't just use `strtoll` for all of them.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [mynewt-core] utzig commented on a change in pull request #2180: sys/config: Support for unsigned integer types

2020-02-12 Thread GitBox
utzig commented on a change in pull request #2180: sys/config: Support for 
unsigned integer types
URL: https://github.com/apache/mynewt-core/pull/2180#discussion_r378323283
 
 

 ##
 File path: sys/config/src/config.c
 ##
 @@ -252,6 +283,21 @@ conf_str_from_value(enum conf_type type, void *vp, char 
*buf, int buf_len)
 case CONF_INT64:
 snprintf(buf, buf_len, "%lld", *(long long *)vp);
 return buf;
+case CONF_UINT8:
+case CONF_UINT16:
+case CONF_UINT32:
+if (type == CONF_UINT8) {
+uval = *(uint8_t *)vp;
+} else if (type == CONF_UINT16) {
+uval = *(uint16_t *)vp;
+} else {
+uval = *(uint32_t *)vp;
+}
+snprintf(buf, buf_len, "%lu", (unsigned long)uval);
+return buf;
+case CONF_UINT64:
+snprintf(buf, buf_len, "%llu", *(unsigned long long *)vp);
 
 Review comment:
   My comment regarding special handling for 64-bit int also applies here...


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services