summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog6
-rw-r--r--src/coding.c11
-rw-r--r--src/composite.h11
3 files changed, 18 insertions, 10 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 4e33ccb0c0d..24161dbda1e 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -2,6 +2,12 @@
* coding.c (EMIT_ONE_BYTE, EMIT_TWO_BYTES): Use unsigned, not int.
This avoids several warnings with gcc -Wstrict-overflow.
+ (DECODE_COMPOSITION_RULE): If the rule is invalid, goto invalid_code
+ directly, rather than having caller test rule sign. This avoids
+ some unnecessary tests.
+ * composite.h (COMPOSITION_ENCODE_RULE_VALID): New macro.
+ (COMPOSITION_ENCODE_RULE): Arguments now must be valid. This
+ affects only one use, in DECODE_COMPOSITION_RULE, which is changed.
* xfont.c (xfont_text_extents): Remove var that was set but not used.
(xfont_open): Avoid unnecessary tests.
diff --git a/src/coding.c b/src/coding.c
index 6e5d0655258..555c29cbdf3 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -3254,13 +3254,13 @@ detect_coding_iso_2022 (struct coding_system *coding,
/* Decode a composition rule C1 and maybe one more byte from the
source, and set RULE to the encoded composition rule. If the rule
- is invalid, set RULE to some negative value. */
+ is invalid, goto invalid_code. */
#define DECODE_COMPOSITION_RULE(rule) \
do { \
rule = c1 - 32; \
if (rule < 0) \
- break; \
+ goto invalid_code; \
if (rule < 81) /* old format (before ver.21) */ \
{ \
int gref = (rule) / 9; \
@@ -3274,9 +3274,10 @@ detect_coding_iso_2022 (struct coding_system *coding,
int b; \
\
ONE_MORE_BYTE (b); \
+ if (! COMPOSITION_ENCODE_RULE_VALID (rule - 81, b - 32)) \
+ goto invalid_code; \
rule = COMPOSITION_ENCODE_RULE (rule - 81, b - 32); \
- if (rule >= 0) \
- rule += 0x100; /* to destinguish it from the old format */ \
+ rule += 0x100; /* Distinguish it from the old format. */ \
} \
} while (0)
@@ -3543,8 +3544,6 @@ decode_coding_iso_2022 (struct coding_system *coding)
int rule;
DECODE_COMPOSITION_RULE (rule);
- if (rule < 0)
- goto invalid_code;
STORE_COMPOSITION_RULE (rule);
continue;
}
diff --git a/src/composite.h b/src/composite.h
index ffdb57a571e..cfb5db0dc6a 100644
--- a/src/composite.h
+++ b/src/composite.h
@@ -148,12 +148,15 @@ extern Lisp_Object composition_temp;
COMPOSITION_DECODE_REFS (rule_code, gref, nref); \
} while (0)
+/* Nonzero if the global reference point GREF and new reference point NREF are
+ valid. */
+#define COMPOSITION_ENCODE_RULE_VALID(gref, nref) \
+ ((unsigned) (gref) < 12 && (unsigned) (nref) < 12)
+
/* Return encoded composition rule for the pair of global reference
- point GREF and new reference point NREF. If arguments are invalid,
- return -1. */
+ point GREF and new reference point NREF. Arguments must be valid. */
#define COMPOSITION_ENCODE_RULE(gref, nref) \
- ((unsigned) (gref) < 12 && (unsigned) (nref) < 12 \
- ? (gref) * 12 + (nref) : -1)
+ ((gref) * 12 + (nref))
/* Data structure that records information about a composition
currently used in some buffers or strings.