Rename ws_label_strcat() to ws_label_strcpy()
The semantics of ws_label_strcat() are closer to g_strlcpy() so rename the function to reflect that.
This commit is contained in:
parent
f55cb116a0
commit
92e1357bb4
26
epan/proto.c
26
epan/proto.c
|
@ -221,7 +221,7 @@ static int hfinfo_mask_bitwidth(const header_field_info *hfinfo);
|
|||
static int hfinfo_container_bitwidth(const header_field_info *hfinfo);
|
||||
|
||||
#define label_concat(dst, pos, src) \
|
||||
ws_label_strcat(dst, ITEM_LABEL_LENGTH, pos, src, 0)
|
||||
ws_label_strcpy(dst, ITEM_LABEL_LENGTH, pos, src, 0)
|
||||
|
||||
static void label_mark_truncated(char *label_str, gsize name_pos);
|
||||
#define LABEL_MARK_TRUNCATED_START(label_str) label_mark_truncated(label_str, 0)
|
||||
|
@ -3819,27 +3819,27 @@ proto_tree_add_item_ret_display_string_and_length(proto_tree *tree, int hfindex,
|
|||
case FT_STRING:
|
||||
value = get_string_value(scope, tvb, start, length, lenretval, encoding);
|
||||
*retval = wmem_alloc(scope, ITEM_LABEL_LENGTH);
|
||||
ws_label_strcat(*retval, ITEM_LABEL_LENGTH, 0, value, label_strcat_flags(hfinfo));
|
||||
ws_label_strcpy(*retval, ITEM_LABEL_LENGTH, 0, value, label_strcat_flags(hfinfo));
|
||||
break;
|
||||
case FT_STRINGZ:
|
||||
value = get_stringz_value(scope, tree, tvb, start, length, lenretval, encoding);
|
||||
*retval = wmem_alloc(scope, ITEM_LABEL_LENGTH);
|
||||
ws_label_strcat(*retval, ITEM_LABEL_LENGTH, 0, value, label_strcat_flags(hfinfo));
|
||||
ws_label_strcpy(*retval, ITEM_LABEL_LENGTH, 0, value, label_strcat_flags(hfinfo));
|
||||
break;
|
||||
case FT_UINT_STRING:
|
||||
value = get_uint_string_value(scope, tree, tvb, start, length, lenretval, encoding);
|
||||
*retval = wmem_alloc(scope, ITEM_LABEL_LENGTH);
|
||||
ws_label_strcat(*retval, ITEM_LABEL_LENGTH, 0, value, label_strcat_flags(hfinfo));
|
||||
ws_label_strcpy(*retval, ITEM_LABEL_LENGTH, 0, value, label_strcat_flags(hfinfo));
|
||||
break;
|
||||
case FT_STRINGZPAD:
|
||||
value = get_stringzpad_value(scope, tvb, start, length, lenretval, encoding);
|
||||
*retval = wmem_alloc(scope, ITEM_LABEL_LENGTH);
|
||||
ws_label_strcat(*retval, ITEM_LABEL_LENGTH, 0, value, label_strcat_flags(hfinfo));
|
||||
ws_label_strcpy(*retval, ITEM_LABEL_LENGTH, 0, value, label_strcat_flags(hfinfo));
|
||||
break;
|
||||
case FT_STRINGZTRUNC:
|
||||
value = get_stringztrunc_value(scope, tvb, start, length, lenretval, encoding);
|
||||
*retval = wmem_alloc(scope, ITEM_LABEL_LENGTH);
|
||||
ws_label_strcat(*retval, ITEM_LABEL_LENGTH, 0, value, label_strcat_flags(hfinfo));
|
||||
ws_label_strcpy(*retval, ITEM_LABEL_LENGTH, 0, value, label_strcat_flags(hfinfo));
|
||||
break;
|
||||
case FT_BYTES:
|
||||
value = tvb_get_ptr(tvb, start, length);
|
||||
|
@ -6374,7 +6374,7 @@ proto_tree_set_representation_value(proto_item *pi, const char *format, va_list
|
|||
/* If possible, Put in the value of the string */
|
||||
str = wmem_strdup_vprintf(PNODE_POOL(pi), format, ap);
|
||||
WS_UTF_8_CHECK(str, -1);
|
||||
ret = ws_label_strcat(fi->rep->representation, ITEM_LABEL_LENGTH, ret, str, 0);
|
||||
ret = ws_label_strcpy(fi->rep->representation, ITEM_LABEL_LENGTH, ret, str, 0);
|
||||
if (ret >= ITEM_LABEL_LENGTH) {
|
||||
/* Uh oh, we don't have enough room. Tell the user
|
||||
* that the field is truncated.
|
||||
|
@ -6401,7 +6401,7 @@ proto_tree_set_representation(proto_item *pi, const char *format, va_list ap)
|
|||
|
||||
str = wmem_strdup_vprintf(PNODE_POOL(pi), format, ap);
|
||||
WS_UTF_8_CHECK(str, -1);
|
||||
ret = ws_label_strcat(fi->rep->representation, ITEM_LABEL_LENGTH, 0, str, 0);
|
||||
ret = ws_label_strcpy(fi->rep->representation, ITEM_LABEL_LENGTH, 0, str, 0);
|
||||
if (ret >= ITEM_LABEL_LENGTH) {
|
||||
/* Uh oh, we don't have enough room. Tell the user
|
||||
* that the field is truncated.
|
||||
|
@ -6706,7 +6706,7 @@ proto_item_fill_display_label(field_info *finfo, gchar *display_label_str, const
|
|||
case FT_STRINGZPAD:
|
||||
case FT_STRINGZTRUNC:
|
||||
str = fvalue_get_string(&finfo->value);
|
||||
label_len = (int)ws_label_strcat(display_label_str, label_str_size, 0, str, label_strcat_flags(hfinfo));
|
||||
label_len = (int)ws_label_strcpy(display_label_str, label_str_size, 0, str, label_strcat_flags(hfinfo));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -7069,7 +7069,7 @@ proto_item_append_text(proto_item *pi, const char *format, ...)
|
|||
str = wmem_strdup_vprintf(PNODE_POOL(pi), format, ap);
|
||||
va_end(ap);
|
||||
WS_UTF_8_CHECK(str, -1);
|
||||
curlen = ws_label_strcat(fi->rep->representation, ITEM_LABEL_LENGTH, curlen, str, 0);
|
||||
curlen = ws_label_strcpy(fi->rep->representation, ITEM_LABEL_LENGTH, curlen, str, 0);
|
||||
if (curlen >= ITEM_LABEL_LENGTH) {
|
||||
/* Uh oh, we don't have enough room. Tell the user
|
||||
* that the field is truncated.
|
||||
|
@ -7112,8 +7112,8 @@ proto_item_prepend_text(proto_item *pi, const char *format, ...)
|
|||
str = wmem_strdup_vprintf(PNODE_POOL(pi), format, ap);
|
||||
va_end(ap);
|
||||
WS_UTF_8_CHECK(str, -1);
|
||||
pos = ws_label_strcat(fi->rep->representation, ITEM_LABEL_LENGTH, 0, str, 0);
|
||||
pos = ws_label_strcat(fi->rep->representation, ITEM_LABEL_LENGTH, pos, representation, 0);
|
||||
pos = ws_label_strcpy(fi->rep->representation, ITEM_LABEL_LENGTH, 0, str, 0);
|
||||
pos = ws_label_strcpy(fi->rep->representation, ITEM_LABEL_LENGTH, pos, representation, 0);
|
||||
/* XXX: As above, if the old representation is close to the label
|
||||
* length, it might already be marked as truncated. */
|
||||
if (pos >= ITEM_LABEL_LENGTH && (strlen(representation) + 4) <= ITEM_LABEL_LENGTH) {
|
||||
|
@ -9151,7 +9151,7 @@ label_fill(char *label_str, gsize pos, const header_field_info *hfinfo, const ch
|
|||
name_pos = pos = label_concat(label_str, pos, hfinfo->name);
|
||||
if (!(hfinfo->display & BASE_NO_DISPLAY_VALUE)) {
|
||||
pos = label_concat(label_str, pos, ": ");
|
||||
pos = ws_label_strcat(label_str, ITEM_LABEL_LENGTH, pos, text ? text : "(null)", label_strcat_flags(hfinfo));
|
||||
pos = ws_label_strcpy(label_str, ITEM_LABEL_LENGTH, pos, text ? text : "(null)", label_strcat_flags(hfinfo));
|
||||
}
|
||||
|
||||
if (pos >= ITEM_LABEL_LENGTH) {
|
||||
|
|
|
@ -804,7 +804,7 @@ static const char _hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
|
|||
* written with enough space.
|
||||
*/
|
||||
size_t
|
||||
ws_label_strcat(char *label_str, size_t buf_size, size_t pos,
|
||||
ws_label_strcpy(char *label_str, size_t buf_size, size_t pos,
|
||||
const uint8_t *str, int flags)
|
||||
{
|
||||
if (pos >= buf_size)
|
||||
|
|
|
@ -193,7 +193,7 @@ void IA5_7BIT_decode(unsigned char * dest, const unsigned char* src, int len);
|
|||
#define FORMAT_LABEL_REPLACE_SPACE (0x1 << 0)
|
||||
|
||||
WS_DLL_PUBLIC
|
||||
size_t ws_label_strcat(char *label_str, size_t bufsize, gsize pos, const uint8_t *str, int flags);
|
||||
size_t ws_label_strcpy(char *label_str, size_t bufsize, gsize pos, const uint8_t *str, int flags);
|
||||
|
||||
/*
|
||||
* Check name is valid. This covers names for display filter fields, dissector
|
||||
|
|
|
@ -25,25 +25,25 @@ void test_label_strcat(void)
|
|||
|
||||
src = "ABCD";
|
||||
pos = 0;
|
||||
pos = ws_label_strcat(label, sizeof(label), pos, src, 0);
|
||||
pos = ws_label_strcpy(label, sizeof(label), pos, src, 0);
|
||||
g_assert_cmpstr(label, ==, "ABCD");
|
||||
g_assert_cmpuint(pos, ==, 4);
|
||||
|
||||
src = "EFGH";
|
||||
pos = ws_label_strcat(label, sizeof(label), pos, src, 0);
|
||||
pos = ws_label_strcpy(label, sizeof(label), pos, src, 0);
|
||||
g_assert_cmpstr(label, ==, "ABCDEFG");
|
||||
g_assert_cmpuint(pos, ==, 8);
|
||||
|
||||
src = "IJKL";
|
||||
pos = 7;
|
||||
pos = ws_label_strcat(label, sizeof(label), pos, src, 0);
|
||||
pos = ws_label_strcpy(label, sizeof(label), pos, src, 0);
|
||||
g_assert_cmpstr(label, ==, "ABCDEFG");
|
||||
g_assert_cmpuint(pos, ==, 11);
|
||||
|
||||
/* UTF-8 multibyte does not fit, do not truncate. */
|
||||
src = "ABCDEF"UTF8_MIDDLE_DOT;
|
||||
pos = 0;
|
||||
pos = ws_label_strcat(label, sizeof(label), pos, src, 0);
|
||||
pos = ws_label_strcpy(label, sizeof(label), pos, src, 0);
|
||||
g_assert_cmpstr(label, ==, "ABCDEF");
|
||||
g_assert_cmpuint(pos, ==, 8); /* Tried to write 8 bytes. */
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ void test_label_strcat_escape_whitespace(void)
|
|||
|
||||
src = "ABCD\n\t\f\r\aE"UTF8_MIDDLE_DOT"Z";
|
||||
dst = "ABCD\\n\\t\\f\\r\\aE"UTF8_MIDDLE_DOT"Z";
|
||||
pos = ws_label_strcat(label, sizeof(label), 0, src, 0);
|
||||
pos = ws_label_strcpy(label, sizeof(label), 0, src, 0);
|
||||
g_assert_cmpstr(label, ==, dst);
|
||||
g_assert_cmpuint(pos, ==, strlen(dst));
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ void test_label_escape_control(void)
|
|||
|
||||
src = "ABCD \x04\x17\xC2\x80 EFG \xC2\x90 HIJ \xC2\x9F Z";
|
||||
dst = "ABCD \\x04\\x17\\u0080 EFG \\u0090 HIJ \\u009F Z";
|
||||
pos = ws_label_strcat(label, sizeof(label), 0, src, 0);
|
||||
pos = ws_label_strcpy(label, sizeof(label), 0, src, 0);
|
||||
g_assert_cmpstr(label, ==, dst);
|
||||
g_assert_cmpuint(pos, ==, strlen(dst));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue