[Patches] snprintf.c : reduce compiler warnings
Steve White
steve.white at aei.mpg.de
Mon Feb 13 07:44:53 CST 2006
Hello,
This is part of a project to reduce the compiler warnings generated by
Cactus Flesh code.
Intel icc in particular complains mightily about automatic type conversions
that could lose data in
src/util/snprintf.c
Changes
-------
Several deliberate conversions are now marked as such with type casts.
Note
----
I ignored one warning. Intel icc complains that
(caps ? 'E' : 'e')
is an int:
util/snprintf.c(733):
warning #810: conversion from "int" to "char" may lose significant bits
econvert[eplace++] = caps ? 'E' : 'e';
You can humour the compiler by casting (caps ? 'E' : 'e') to char, but
this seems to be just wrong.
According to K&R 2nd ed A7.16:
"if both [the second and third operands] are void, or structures or
unions of the same type, or pointers to objects of the same type,
the result has the common type."
Am I missing something? I'll see if Intel has a bug report on this.
Testing
-------
I ran all the testsuites against a copy with no changes, and got
identical results.
Find attached the patch.
--
Steve White : Programmer
Max-Planck-Institut für Gravitationsphysik Albert-Einstein-Institut
Am Mühlenberg 1, D-14476 Golm, Germany +49-331-567-7625
-------------- next part --------------
Index: src/util/snprintf.c
===================================================================
RCS file: /cactusdevcvs/Cactus/src/util/snprintf.c,v
retrieving revision 1.10
diff -u -r1.10 snprintf.c
--- src/util/snprintf.c 5 Apr 2005 11:37:07 -0000 1.10
+++ src/util/snprintf.c 13 Feb 2006 13:31:55 -0000
@@ -365,7 +365,8 @@
total += fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags);
break;
case 'c':
- total += dopr_outch (buffer, &currlen, maxlen, va_arg (args, int));
+ total += dopr_outch (buffer, &currlen, maxlen,
+ (char)va_arg (args, int));
break;
case 's':
strvalue = va_arg (args, char *);
@@ -381,7 +382,7 @@
{
short int *num;
num = va_arg (args, short int *);
- *num = currlen;
+ *num = (short int)currlen;
}
else if (cflags == DP_C_LONG)
{
@@ -538,7 +539,7 @@
/* Sign */
if (signvalue)
- total += dopr_outch (buffer, currlen, maxlen, signvalue);
+ total += dopr_outch (buffer, currlen, maxlen, (char)signvalue);
/* Zeros */
if (zpadlen > 0)
@@ -590,7 +591,7 @@
{
long intpart;
- intpart = value;
+ intpart = (long)value;
value = value - intpart;
if (value >= 0.5)
intpart++;
@@ -668,7 +669,7 @@
}
}
- intpart = ufvalue;
+ intpart = (long)ufvalue;
/*
* Sorry, we only support 9 digits past the decimal because of our
@@ -685,7 +686,7 @@
if (fracpart >= mypow10 (max))
{
intpart++;
- fracpart -= mypow10 (max);
+ fracpart -= (long)mypow10 (max);
}
#ifdef DEBUG_SNPRINTF
@@ -752,7 +753,7 @@
{
if (signvalue)
{
- total += dopr_outch (buffer, currlen, maxlen, signvalue);
+ total += dopr_outch (buffer, currlen, maxlen, (char)signvalue);
--padlen;
signvalue = 0;
}
@@ -768,7 +769,7 @@
--padlen;
}
if (signvalue)
- total += dopr_outch (buffer, currlen, maxlen, signvalue);
+ total += dopr_outch (buffer, currlen, maxlen, (char)signvalue);
while (iplace > 0)
total += dopr_outch (buffer, currlen, maxlen, iconvert[--iplace]);
More information about the Patches
mailing list