|
|
@@ -93,36 +93,9 @@ static int ncd_read_uintmax (NCDValRef string, uintmax_t *out)
|
|
|
return parse_unsigned_integer_bin(NCDVal_StringData(string), length, out);
|
|
|
}
|
|
|
|
|
|
- if (length == 0) {
|
|
|
- return 0;
|
|
|
- }
|
|
|
+ b_cstring cstr = NCDVal_StringCstring(string);
|
|
|
|
|
|
- uintmax_t n = 0;
|
|
|
-
|
|
|
- size_t pos = 0;
|
|
|
- while (pos < length) {
|
|
|
- const char *chunk_data;
|
|
|
- size_t chunk_len;
|
|
|
- NCDVal_StringGetPtr(string, pos, length - pos, &chunk_data, &chunk_len);
|
|
|
- for (size_t i = 0; i < chunk_len; i++) {
|
|
|
- int digit = decode_decimal_digit(chunk_data[i]);
|
|
|
- if (digit < 0) {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- if (n > UINTMAX_MAX / 10) {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- n *= 10;
|
|
|
- if (digit > UINTMAX_MAX - n) {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- n += digit;
|
|
|
- }
|
|
|
- pos += chunk_len;
|
|
|
- }
|
|
|
-
|
|
|
- *out = n;
|
|
|
- return 1;
|
|
|
+ return parse_unsigned_integer_cstr(cstr, 0, cstr.length, out);
|
|
|
}
|
|
|
|
|
|
static int ncd_read_time (NCDValRef string, btime_t *out)
|
|
|
@@ -154,15 +127,14 @@ static NCD_string_id_t ncd_get_string_id (NCDValRef string, NCDStringIndex *stri
|
|
|
return NCDStringIndex_GetBin(string_index, NCDVal_StringData(string), NCDVal_StringLength(string));
|
|
|
}
|
|
|
|
|
|
- size_t length = NCDVal_StringLength(string);
|
|
|
+ b_cstring cstr = NCDVal_StringCstring(string);
|
|
|
|
|
|
- char *temp = BAlloc(length);
|
|
|
+ char *temp = b_cstring_strdup(cstr, 0, cstr.length);
|
|
|
if (!temp) {
|
|
|
return -1;
|
|
|
}
|
|
|
- NCDVal_StringCopyOut(string, 0, length, temp);
|
|
|
|
|
|
- NCD_string_id_t res = NCDStringIndex_GetBin(string_index, temp, length);
|
|
|
+ NCD_string_id_t res = NCDStringIndex_GetBin(string_index, temp, cstr.length);
|
|
|
BFree(temp);
|
|
|
|
|
|
return res;
|
|
|
@@ -194,18 +166,9 @@ static char * ncd_strdup (NCDValRef stringnonulls)
|
|
|
return b_strdup_bin(NCDVal_StringData(stringnonulls), length);
|
|
|
}
|
|
|
|
|
|
- if (length == SIZE_MAX) {
|
|
|
- return NULL;
|
|
|
- }
|
|
|
-
|
|
|
- char *data = BAlloc(length + 1);
|
|
|
- if (!data) {
|
|
|
- return NULL;
|
|
|
- }
|
|
|
- NCDVal_StringCopyOut(stringnonulls, 0, length, data);
|
|
|
- data[length] = '\0';
|
|
|
+ b_cstring cstr = NCDVal_StringCstring(stringnonulls);
|
|
|
|
|
|
- return data;
|
|
|
+ return b_cstring_strdup(cstr, 0, cstr.length);
|
|
|
}
|
|
|
|
|
|
#endif
|