Generally speaking the compiler warnings you're talking about cause
false alarms so often that they're more trouble than they're worth. For
example, if P and Q are pointers into the same array and P <= Q, it's
quite normal to compute Q-P and store the result into a size_t variable.
Although I'm not sure why you selected the casts in question to attack
first, for casts to unsigned char how about the attached patch instead?
The general idea is to avoid casts when possible, as they're too
powerful in C. The characters in question are all ASCII so sign
extension shouldn't matter.
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 3797ce1..5254c8c 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -1886,7 +1886,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
else
{
do
- result[length++] = (unsigned char) *cp++;
+ result[length++] = *cp++;
while (--n > 0);
}
}
@@ -4793,7 +4793,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
{
const FCHAR_T *mp = dp->width_start;
do
- *fbp++ = (unsigned char) *mp++;
+ *fbp++ = *mp++;
while (--n > 0);
}
}
@@ -4814,7 +4814,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
{
const FCHAR_T *mp = dp->precision_start;
do
- *fbp++ = (unsigned char) *mp++;
+ *fbp++ = *mp++;
while (--n > 0);
}
}
@@ -5382,7 +5382,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
tmpsrc += count;
tmpdst += count;
for (n = count; n > 0; n--)
- *--tmpdst = (unsigned char) *--tmpsrc;
+ *--tmpdst = *--tmpsrc;
}
}
#endif