|
|
|
@ -53,7 +53,7 @@ char *gpr_strdup(const char *src) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
len = strlen(src) + 1; |
|
|
|
|
dst = gpr_malloc(len); |
|
|
|
|
dst = (char *)gpr_malloc(len); |
|
|
|
|
|
|
|
|
|
memcpy(dst, src, len); |
|
|
|
|
|
|
|
|
@ -74,13 +74,13 @@ static dump_out dump_out_create(void) { |
|
|
|
|
static void dump_out_append(dump_out *out, char c) { |
|
|
|
|
if (out->length == out->capacity) { |
|
|
|
|
out->capacity = GPR_MAX(8, 2 * out->capacity); |
|
|
|
|
out->data = gpr_realloc(out->data, out->capacity); |
|
|
|
|
out->data = (char *)gpr_realloc(out->data, out->capacity); |
|
|
|
|
} |
|
|
|
|
out->data[out->length++] = c; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void hexdump(dump_out *out, const char *buf, size_t len) { |
|
|
|
|
static const char hex[16] = "0123456789abcdef"; |
|
|
|
|
static const char *hex = "0123456789abcdef"; |
|
|
|
|
|
|
|
|
|
const uint8_t *const beg = (const uint8_t *)buf; |
|
|
|
|
const uint8_t *const end = beg + len; |
|
|
|
@ -124,16 +124,16 @@ char *gpr_dump(const char *buf, size_t len, uint32_t flags) { |
|
|
|
|
|
|
|
|
|
int gpr_parse_bytes_to_uint32(const char *buf, size_t len, uint32_t *result) { |
|
|
|
|
uint32_t out = 0; |
|
|
|
|
uint32_t new; |
|
|
|
|
uint32_t new_val; |
|
|
|
|
size_t i; |
|
|
|
|
|
|
|
|
|
if (len == 0) return 0; /* must have some bytes */ |
|
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) { |
|
|
|
|
if (buf[i] < '0' || buf[i] > '9') return 0; /* bad char */ |
|
|
|
|
new = 10 * out + (uint32_t)(buf[i] - '0'); |
|
|
|
|
if (new < out) return 0; /* overflow */ |
|
|
|
|
out = new; |
|
|
|
|
new_val = 10 * out + (uint32_t)(buf[i] - '0'); |
|
|
|
|
if (new_val < out) return 0; /* overflow */ |
|
|
|
|
out = new_val; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
*result = out; |
|
|
|
@ -201,7 +201,7 @@ int gpr_parse_nonnegative_int(const char *value) { |
|
|
|
|
char *gpr_leftpad(const char *str, char flag, size_t length) { |
|
|
|
|
const size_t str_length = strlen(str); |
|
|
|
|
const size_t out_length = str_length > length ? str_length : length; |
|
|
|
|
char *out = gpr_malloc(out_length + 1); |
|
|
|
|
char *out = (char *)gpr_malloc(out_length + 1); |
|
|
|
|
memset(out, flag, out_length - str_length); |
|
|
|
|
memcpy(out + out_length - str_length, str, str_length); |
|
|
|
|
out[out_length] = 0; |
|
|
|
@ -225,7 +225,7 @@ char *gpr_strjoin_sep(const char **strs, size_t nstrs, const char *sep, |
|
|
|
|
if (nstrs > 0) { |
|
|
|
|
out_length += sep_len * (nstrs - 1); /* separators */ |
|
|
|
|
} |
|
|
|
|
out = gpr_malloc(out_length); |
|
|
|
|
out = (char *)gpr_malloc(out_length); |
|
|
|
|
out_length = 0; |
|
|
|
|
for (i = 0; i < nstrs; i++) { |
|
|
|
|
const size_t slen = strlen(strs[i]); |
|
|
|
@ -256,7 +256,7 @@ void gpr_strvec_destroy(gpr_strvec *sv) { |
|
|
|
|
void gpr_strvec_add(gpr_strvec *sv, char *str) { |
|
|
|
|
if (sv->count == sv->capacity) { |
|
|
|
|
sv->capacity = GPR_MAX(sv->capacity + 8, sv->capacity * 2); |
|
|
|
|
sv->strs = gpr_realloc(sv->strs, sizeof(char *) * sv->capacity); |
|
|
|
|
sv->strs = (char **)gpr_realloc(sv->strs, sizeof(char *) * sv->capacity); |
|
|
|
|
} |
|
|
|
|
sv->strs[sv->count++] = str; |
|
|
|
|
} |
|
|
|
@ -278,12 +278,12 @@ int gpr_stricmp(const char *a, const char *b) { |
|
|
|
|
|
|
|
|
|
static void add_string_to_split(const char *beg, const char *end, char ***strs, |
|
|
|
|
size_t *nstrs, size_t *capstrs) { |
|
|
|
|
char *out = gpr_malloc((size_t)(end - beg) + 1); |
|
|
|
|
char *out = (char *)gpr_malloc((size_t)(end - beg) + 1); |
|
|
|
|
memcpy(out, beg, (size_t)(end - beg)); |
|
|
|
|
out[end - beg] = 0; |
|
|
|
|
if (*nstrs == *capstrs) { |
|
|
|
|
*capstrs = GPR_MAX(8, 2 * *capstrs); |
|
|
|
|
*strs = gpr_realloc(*strs, sizeof(*strs) * *capstrs); |
|
|
|
|
*strs = (char **)gpr_realloc(*strs, sizeof(*strs) * *capstrs); |
|
|
|
|
} |
|
|
|
|
(*strs)[*nstrs] = out; |
|
|
|
|
++*nstrs; |
|
|
|
|