Browse Source

[core] li_tohex_lc() explicitly uses lc hex chars

remove buffer_copy_string_hex()
personal/stbuehler/fix-fdevent
Glenn Strauss 4 years ago
parent
commit
d3cf141d14
  1. 23
      src/buffer.c
  2. 6
      src/buffer.h

23
src/buffer.c

@ -444,24 +444,27 @@ int buffer_is_equal_right_len(const buffer *b1, const buffer *b2, size_t len) {
return 0 == memcmp(b1->ptr + b1->used - 1 - len, b2->ptr + b2->used - 1 - len, len);
}
void li_tohex(char *buf, size_t buf_len, const char *s, size_t s_len) {
size_t i;
void li_tohex_lc(char *buf, size_t buf_len, const char *s, size_t s_len) {
force_assert(2 * s_len > s_len);
force_assert(2 * s_len < buf_len);
for (i = 0; i < s_len; i++) {
buf[2*i] = hex_chars[(s[i] >> 4) & 0x0F];
buf[2*i+1] = hex_chars[s[i] & 0x0F];
for (size_t i = 0; i < s_len; ++i) {
buf[2*i] = hex_chars_lc[(s[i] >> 4) & 0x0F];
buf[2*i+1] = hex_chars_lc[s[i] & 0x0F];
}
buf[2*s_len] = '\0';
}
void buffer_copy_string_hex(buffer *b, const char *in, size_t in_len) {
/* overflow protection */
force_assert(in_len * 2 > in_len);
void li_tohex_uc(char *buf, size_t buf_len, const char *s, size_t s_len) {
force_assert(2 * s_len > s_len);
force_assert(2 * s_len < buf_len);
buffer_string_set_length(b, 2 * in_len);
li_tohex(b->ptr, buffer_string_length(b)+1, in, in_len);
for (size_t i = 0; i < s_len; ++i) {
buf[2*i] = hex_chars_uc[(s[i] >> 4) & 0x0F];
buf[2*i+1] = hex_chars_uc[s[i] & 0x0F];
}
buf[2*s_len] = '\0';
}

6
src/buffer.h

@ -68,8 +68,6 @@ void buffer_string_set_length(buffer *b, size_t len);
void buffer_copy_string(buffer *b, const char *s);
void buffer_copy_string_len(buffer *b, const char *s, size_t s_len);
void buffer_copy_buffer(buffer *b, const buffer *src);
/* convert input to hex and store in buffer */
void buffer_copy_string_hex(buffer *b, const char *in, size_t in_len);
void buffer_append_string(buffer *b, const char *s);
void buffer_append_string_len(buffer *b, const char *s, size_t s_len);
@ -88,7 +86,9 @@ void li_itostrn(char *buf, size_t buf_len, intmax_t val);
void li_utostrn(char *buf, size_t buf_len, uintmax_t val);
/* buf must be (at least) 2*s_len + 1 big. uses lower-case hex letters. */
void li_tohex(char *buf, size_t buf_len, const char *s, size_t s_len);
#define li_tohex(buf,buf_len,s,s_len) li_tohex_lc((buf),(buf_len),(s),(s_len))
void li_tohex_lc(char *buf, size_t buf_len, const char *s, size_t s_len);
void li_tohex_uc(char *buf, size_t buf_len, const char *s, size_t s_len);
/* NULL buffer or empty buffer (used == 0);
* unset "string" (buffer) config options are initialized to used == 0,

Loading…
Cancel
Save