aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2022-10-15 14:16:10 -0700
committerGuy Harris <gharris@sonic.net>2022-10-15 14:16:10 -0700
commitf86a0d5ab4c408e8a7907f9e54194076820cc268 (patch)
tree2e021d71b3a772ffe40284505d736d6ade72dbdf
parentab7b71605c078c35286e85f618605c9fc53c1dbd (diff)
Use wmem_strbuf_append_unichar_repl() to append a REPLACEMENT CHARACTER.
Replace several instances in which a REPLACEMENT CHARACTER was being appended to a wmem_strbuf with a call to wmem_strbuf_append_unichar_repl(). This reduces the number of explicit 0x00fffd or 0xfffd or... in the code.
-rw-r--r--epan/charsets.c34
-rw-r--r--epan/dissectors/packet-json.c2
-rw-r--r--epan/dissectors/packet-per.c6
-rw-r--r--epan/dissectors/packet-x11.c4
-rw-r--r--epan/tvbuff.c5
5 files changed, 22 insertions, 29 deletions
diff --git a/epan/charsets.c b/epan/charsets.c
index 637709e982..59da769aa1 100644
--- a/epan/charsets.c
+++ b/epan/charsets.c
@@ -77,7 +77,7 @@ get_ascii_string(wmem_allocator_t *scope, const guint8 *ptr, gint length)
if (ch < 0x80)
wmem_strbuf_append_c(str, ch);
else
- wmem_strbuf_append_unichar(str, UNREPL);
+ wmem_strbuf_append_unichar_repl(str);
ptr++;
length--;
}
@@ -120,7 +120,7 @@ get_utf_8_string(wmem_allocator_t *scope, const guint8 *ptr, gint length)
if (ch < 0x80) {
wmem_strbuf_append_c(str, ch);
} else if (ch < 0xc2 || ch > 0xf4) {
- wmem_strbuf_append_unichar(str, UNREPL);
+ wmem_strbuf_append_unichar_repl(str);
} else {
prev = ptr;
if (ch < 0xe0) { /* 110xxxxx, 2 byte char */
@@ -130,25 +130,25 @@ get_utf_8_string(wmem_allocator_t *scope, const guint8 *ptr, gint length)
ptr++;
length--;
if (length < 1) {
- wmem_strbuf_append_unichar(str, UNREPL);
+ wmem_strbuf_append_unichar_repl(str);
continue;
}
switch (ch) {
case 0xe0:
if (*ptr < 0xa0 || *ptr > 0xbf) {
- wmem_strbuf_append_unichar(str, UNREPL);
+ wmem_strbuf_append_unichar_repl(str);
continue;
}
break;
case 0xed:
if (*ptr < 0x80 || *ptr > 0x9f) {
- wmem_strbuf_append_unichar(str, UNREPL);
+ wmem_strbuf_append_unichar_repl(str);
continue;
}
break;
default:
if (*ptr < 0x80 || *ptr > 0xbf) {
- wmem_strbuf_append_unichar(str, UNREPL);
+ wmem_strbuf_append_unichar_repl(str);
continue;
}
}
@@ -157,36 +157,36 @@ get_utf_8_string(wmem_allocator_t *scope, const guint8 *ptr, gint length)
ptr++;
length--;
if (length < 1) {
- wmem_strbuf_append_unichar(str, UNREPL);
+ wmem_strbuf_append_unichar_repl(str);
continue;
}
switch (ch) {
case 0xf0:
if (*ptr < 0x90 || *ptr > 0xbf) {
- wmem_strbuf_append_unichar(str, UNREPL);
+ wmem_strbuf_append_unichar_repl(str);
continue;
}
break;
case 0xf4:
if (*ptr < 0x80 || *ptr > 0x8f) {
- wmem_strbuf_append_unichar(str, UNREPL);
+ wmem_strbuf_append_unichar_repl(str);
continue;
}
break;
default:
if (*ptr < 0x80 || *ptr > 0xbf) {
- wmem_strbuf_append_unichar(str, UNREPL);
+ wmem_strbuf_append_unichar_repl(str);
continue;
}
}
ptr++;
length--;
if (length < 1) {
- wmem_strbuf_append_unichar(str, UNREPL);
+ wmem_strbuf_append_unichar_repl(str);
continue;
}
if (*ptr < 0x80 || *ptr > 0xbf) {
- wmem_strbuf_append_unichar(str, UNREPL);
+ wmem_strbuf_append_unichar_repl(str);
continue;
}
}
@@ -194,11 +194,11 @@ get_utf_8_string(wmem_allocator_t *scope, const guint8 *ptr, gint length)
ptr++;
length--;
if (length < 1) {
- wmem_strbuf_append_unichar(str, UNREPL);
+ wmem_strbuf_append_unichar_repl(str);
continue;
}
if (*ptr < 0x80 || *ptr > 0xbf) {
- wmem_strbuf_append_unichar(str, UNREPL);
+ wmem_strbuf_append_unichar_repl(str);
continue;
} else {
wmem_strbuf_append_len(str, prev, unichar_len);
@@ -257,7 +257,7 @@ get_iso_646_string(wmem_allocator_t *scope, const guint8 *ptr, gint length, cons
if (ch < 0x80)
wmem_strbuf_append_unichar(str, table[ch]);
else
- wmem_strbuf_append_unichar(str, UNREPL);
+ wmem_strbuf_append_unichar_repl(str);
ptr++;
length--;
}
@@ -1501,7 +1501,7 @@ get_string_enc_iconv(wmem_allocator_t *scope, const guint8 *ptr, gint length, co
switch (errno) {
case EINVAL:
/* Incomplete sequence at the end, not an error */
- wmem_strbuf_append_unichar(str, UNREPL);
+ wmem_strbuf_append_unichar_repl(str);
inbytes = 0;
break;
case E2BIG:
@@ -1519,7 +1519,7 @@ get_string_enc_iconv(wmem_allocator_t *scope, const guint8 *ptr, gint length, co
max_subpart = MAX(1, max_subpart-1);
ptr += max_subpart;
inbytes -= max_subpart;
- wmem_strbuf_append_unichar(str, UNREPL);
+ wmem_strbuf_append_unichar_repl(str);
outptr = tempstr;
outbytes = tempstr_size;
break;
diff --git a/epan/dissectors/packet-json.c b/epan/dissectors/packet-json.c
index 1f9253a1cc..6bd0cacfaa 100644
--- a/epan/dissectors/packet-json.c
+++ b/epan/dissectors/packet-json.c
@@ -347,7 +347,7 @@ json_string_unescape(const char *string, size_t *length_ptr)
}
else
{
- wmem_strbuf_append_unichar(output_string_buffer, 0xFFFD);
+ wmem_strbuf_append_unichar_repl(output_string_buffer);
}
}
else
diff --git a/epan/dissectors/packet-per.c b/epan/dissectors/packet-per.c
index 0065d13c0e..e77b87b531 100644
--- a/epan/dissectors/packet-per.c
+++ b/epan/dissectors/packet-per.c
@@ -623,8 +623,6 @@ DEBUG_ENTRY("dissect_per_sequence_of");
return offset;
}
-#define UNREPL 0xFFFD
-
/* XXX we don't do >64k length strings yet */
static guint32
dissect_per_restricted_character_string_sorted(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index, int min_len, int max_len, gboolean has_extension, guint16 lb, guint16 ub, const char *alphabet, int alphabet_length, tvbuff_t **value_tvb)
@@ -759,7 +757,7 @@ DEBUG_ENTRY("dissect_per_restricted_character_string");
}
if(use_canonical_order == FALSE){
if (val > ub || val < lb) {
- wmem_strbuf_append_unichar(buf, UNREPL);
+ wmem_strbuf_append_unichar_repl(buf);
} else {
wmem_strbuf_append_c(buf, val);
}
@@ -767,7 +765,7 @@ DEBUG_ENTRY("dissect_per_restricted_character_string");
if (val < alphabet_length){
wmem_strbuf_append_c(buf, alphabet[val]);
} else {
- wmem_strbuf_append_unichar(buf, UNREPL);
+ wmem_strbuf_append_unichar_repl(buf);
}
}
}
diff --git a/epan/dissectors/packet-x11.c b/epan/dissectors/packet-x11.c
index 1a2ac6acde..18b5b2f2b4 100644
--- a/epan/dissectors/packet-x11.c
+++ b/epan/dissectors/packet-x11.c
@@ -2223,8 +2223,6 @@ static int stringIsActuallyAn8BitString(tvbuff_t *tvb, int offset, guint length)
return TRUE;
}
-#define UNREPL 0x00FFFD
-
/* XXX - assumes that the string encoding is ASCII; even if 0x00 through
0x7F are ASCII, 0x80 through 0xFF might not be, and even 0x00 through
0x7F aren't necessarily ASCII. */
@@ -2241,7 +2239,7 @@ static char *tvb_get_ascii_string16(tvbuff_t *tvb, int offset, guint length)
if (ch < 0x80)
wmem_strbuf_append_c(str, ch);
else
- wmem_strbuf_append_unichar(str, UNREPL);
+ wmem_strbuf_append_unichar_repl(str);
offset++;
}
return wmem_strbuf_finalize(str);
diff --git a/epan/tvbuff.c b/epan/tvbuff.c
index 99378f1c58..344d811ff3 100644
--- a/epan/tvbuff.c
+++ b/epan/tvbuff.c
@@ -2654,9 +2654,6 @@ tvb_format_stringzpad_wsp(wmem_allocator_t* allocator, tvbuff_t *tvb, const gint
return format_text_wsp(allocator, ptr, stringlen);
}
-/* Unicode REPLACEMENT CHARACTER */
-#define UNREPL 0x00FFFD
-
/*
* All string functions below take a scope as an argument.
*
@@ -3062,7 +3059,7 @@ tvb_get_apn_string(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset,
if (ch < 0x80)
wmem_strbuf_append_c(str, ch);
else
- wmem_strbuf_append_unichar(str, UNREPL);
+ wmem_strbuf_append_unichar_repl(str);
ptr++;
label_len--;
length--;