[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/3] Fix incompatible pointer type warning in unicode.c
From: |
Eduardo A . Bustamante López |
Subject: |
[PATCH 3/3] Fix incompatible pointer type warning in unicode.c |
Date: |
Fri, 4 Jan 2019 12:25:42 -0800 |
The warning is raised by Clang (7.0.1-4) when sizeof(wchar_t) is 4
| dualbus@system76-pc:~/src/gnu/bash/lib/sh$ make unicode.o
| clang -c -I. -I../.. -I../.. -I../../lib -I../../include -I.
-DHAVE_CONFIG_H -DSHELL -ggdb -O0 -Wno-parentheses -Wno-format-security
unicode.c
| unicode.c:262:69: warning: incompatible pointer types passing 'wchar_t [3]'
to parameter of type 'unsigned short *' [-Wincompatible-pointer-types]
| else if (sizeof (wchar_t) == 2 && c <= 0x10ffff && u32toutf16 (c, ws))
| ^~
| 1 warning generated.
dualbus@system76-pc:~/src/gnu/bash$ clang -v 2>&1 | head -n2
clang version 7.0.1-4 (tags/RELEASE_701/final)
Target: x86_64-pc-linux-gnu
In practice, this isn't really a problem because the compiler should optimize
away the `sizeof(wchar_t) == 2' branch. Still, it's easy to fix.
I think that maybe there should be some sort of compile-time assertion inside
`u32toutf16`, to ensure it's only used when `sizeof(wchar_t) == 2', but I don't
know how to do that.
---
lib/sh/unicode.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/sh/unicode.c b/lib/sh/unicode.c
index fe13c4a0..99c422ab 100644
--- a/lib/sh/unicode.c
+++ b/lib/sh/unicode.c
@@ -216,21 +216,21 @@ u32toutf8 (wc, s)
int
u32toutf16 (c, s)
u_bits32_t c;
- unsigned short *s;
+ wchar_t *s;
{
int l;
l = 0;
if (c < 0x0d800 || (c >= 0x0e000 && c <= 0x0ffff))
{
- s[0] = (unsigned short) (c & 0xFFFF);
+ s[0] = (wchar_t) (c & 0xFFFF);
l = 1;
}
else if (c >= 0x10000 && c <= 0x010ffff)
{
c -= 0x010000;
- s[0] = (unsigned short)((c >> 10) + 0xd800);
- s[1] = (unsigned short)((c & 0x3ff) + 0xdc00);
+ s[0] = (wchar_t)((c >> 10) + 0xd800);
+ s[1] = (wchar_t)((c & 0x3ff) + 0xdc00);
l = 2;
}
s[l] = 0;
--
2.20.1