Dear Maintainer,
Add the first parentheses to "CL_SEP" and the second at the end of
the line where "CL_SEP" is used, to avoid warnings from the compiler of type:
pack_name.c:30:17: warning: suggest parentheses around arithmetic in operand of '|' [-Wparentheses]
30 | #define CL_SEP | 0x4000 + /* address separator */
| ^
pack_name.c:78:25: note: in expansion of macro 'CL_SEP'
78 | /* ! */ CL_SPACE CL_SEP SEP_BANG,
| ^~~~~~
Add parentheses around "Classic[c]" and "CL_RANGE" to avoid
warnings of type:
pack_name.c:35:34: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
35 | #define BEGIN_RANGE(c) (Class[c] & CL_RANGE(0))
| ^
Add the case for an escape (\\).
Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
---
pack_name.c | 34 +++++++++++++++++++++++++---------
1 file changed, 25 insertions(+), 9 deletions(-)
diff --git a/pack_name.c b/pack_name.c
index 7441854..e99963f 100644
--- a/pack_name.c
+++ b/pack_name.c
@@ -27,16 +27,21 @@
#define CL_RANGE(c) 0x0800+c/* space range, end with c */
#define CL_HYPHEN 0x1000 /* convert to - */
#define CL_STOP 0x2000 /* discard rest of name */
-#define CL_SEP | 0x4000 + /* address separator */
+/*
+ Notice the single '(' in the definition of CL_SEP,
+ therefore an "extra" ')' is needed where it is used.
+*/
+#define CL_SEP | ( 0x4000 + /* address separator */
-#define IS_OK(c) (Class[c] & CL_OK)
+#define IS_OK(c) (Class[c] & CL_OK)
#define IS_SPACE(c) (Class[c] & CL_SPACE)
#define IGNORE(c) (c & 0x80 || Class[c] & CL_IGNORE)
-#define BEGIN_RANGE(c) (Class[c] & CL_RANGE(0))
+#define BEGIN_RANGE(c) ((Class[c]) & (CL_RANGE(0)))
#define END_RANGE(c) (Class[c] & 0xff)
#define IS_HYPHEN(c) (Class[c] & CL_HYPHEN)
#define IS_STOP(c) (Class[c] & CL_STOP)
-#define IS_SEPARATOR(c) (Class[c] & (0 CL_SEP 0))
+/* CL_SEP contains '(' */
+#define IS_SEPARATOR(c) ((Class[c]) & (0 CL_SEP 0)))
int old_packname = 0; /* Default to new behavior */
@@ -75,11 +80,11 @@ static short Class[128] = {
/* US */ CL_IGNORE,
/* space */ CL_SPACE,
- /* ! */ CL_SPACE CL_SEP SEP_BANG,
+ /* ! */ (CL_SPACE) CL_SEP (SEP_BANG)),
/* " */ CL_RANGE('"'),
/* # */ CL_OK,
/* $ */ CL_OK,
- /* % */ CL_OK CL_SEP SEP_PERCENT,
+ /* % */ (CL_OK) CL_SEP (SEP_PERCENT)),
/* & */ CL_OK,
/* ' */ CL_OK,
/* ( */ CL_OK,
@@ -88,7 +93,7 @@ static short Class[128] = {
/* + */ CL_HYPHEN,
/* , */ CL_STOP,
/* - */ CL_HYPHEN,
- /* . */ CL_SPACE CL_SEP SEP_DOT,
+ /* . */ (CL_SPACE) CL_SEP (SEP_DOT)),
/* / */ CL_OK,
/* 0 */ CL_OK,
/* 1 */ CL_OK,
@@ -106,7 +111,7 @@ static short Class[128] = {
/* = */ CL_HYPHEN,
/* > */ CL_IGNORE,
/* ? */ CL_IGNORE,
- /* @ */ CL_OK CL_SEP SEP_AMPERSAND,
+ /* @ */ (CL_OK) CL_SEP (SEP_AMPERSAND)),
/* A */ CL_OK,
/* B */ CL_OK,
/* C */ CL_OK,
@@ -137,7 +142,7 @@ static short Class[128] = {
/* \ */ CL_OK,
/* ] */ CL_OK,
/* ^ */ CL_IGNORE,
- /* _ */ CL_SPACE CL_SEP SEP_SCORE,
+ /* _ */ (CL_SPACE) CL_SEP (SEP_SCORE)),
/* ` */ CL_IGNORE,
/* a */ CL_OK,
/* b */ CL_OK,
@@ -190,6 +195,7 @@ pack_name(char *dest, char *source, int length)
int lfirst, lmiddle, llast;
char namebuf[129];
char *separator[SEP_MAXIMUM];
+ int escaped = 0;
dest[0] = NUL;
@@ -214,6 +220,16 @@ new_partition:
for (i = SEP_MAXIMUM; --i >= 0; separator[i] = NULL);
while ((c = *p++)) {
+ if (c == '\\' && ! escaped) {
+ escaped = 1;
+ continue;
+ }
+ if (escaped) {
+ escaped = 0;
+ *q++ = c;
+ continue;
+ }
+
if (c == '<') {
while (q > namebuf && q[-1] == SP)
q--;