[GitHub] [mynewt-core] ccollins476ad commented on a change in pull request #2180: sys/config: Support for unsigned integer types
ccollins476ad 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_r378435306 ## 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: OK @utzig, you convinced me to change everything :). I also noticed `conf_value_from_str()` had a bug in its range checks for signed integers so I have fixed that. Would you mind taking a look at the latest commits? 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] ccollins476ad commented on a change in pull request #2180: sys/config: Support for unsigned integer types
ccollins476ad 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_r378435306 ## 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: OK @utzig, you convinced me to change everything :). I also noticed `conf_value_from_str()` had a bug in its range checks for signed integers, so I have fixed that. Would you mind taking a look at the latest commits? 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] ccollins476ad commented on a change in pull request #2180: sys/config: Support for unsigned integer types
ccollins476ad 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_r378422805 ## 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: Thanks, I agree here too. I would rather not change the old code and risk breaking something. And I don't change the old code, I think it is best to keep the new code consistent with the old. 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] ccollins476ad commented on a change in pull request #2180: sys/config: Support for unsigned integer types
ccollins476ad 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_r378419873 ## 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 agree. My guess is that the "ll" versions of these functions felt too heavy weight to use for the <=32-bit types. If I were implementing it from scratch, I think I would just use the "ll" functions across the board. I am reluctant to change this existing code though... this feels like an easy place to introduce a bug. 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] ccollins476ad commented on a change in pull request #2180: sys/config: Support for unsigned integer types
ccollins476ad 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_r37842 ## 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: Good point. I will change it. 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