[PATCH:libXfont 3/4] Fix printf warnings about incorrect argument types
Jeremy Huddleston
jeremyhu at apple.com
Sun Oct 23 16:53:59 PDT 2011
Why not change the format string to use %ld for sizeof() instead of casting?
For the others (and this one if you feel strongly about the casting):
Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
On Oct 21, 2011, at 20:56, Alan Coopersmith wrote:
> Mostly due to difference between sizeof & int on 64-bit platforms
>
> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
> ---
> src/bitmap/bdfread.c | 22 ++++++++++++----------
> src/bitmap/bdfutils.c | 7 ++++---
> src/bitmap/pcfread.c | 30 +++++++++++++++++++-----------
> src/bitmap/pcfwrite.c | 3 ++-
> src/bitmap/snfread.c | 6 ++++--
> 5 files changed, 41 insertions(+), 27 deletions(-)
>
> diff --git a/src/bitmap/bdfread.c b/src/bitmap/bdfread.c
> index 0fed688..e2770dc 100644
> --- a/src/bitmap/bdfread.c
> +++ b/src/bitmap/bdfread.c
> @@ -291,13 +291,13 @@ bdfReadCharacters(FontFilePtr file, FontPtr pFont, bdfFileState *pState,
> }
> if (nchars > INT32_MAX / sizeof(CharInfoRec)) {
> bdfError("Couldn't allocate pCI (%d*%d)\n", nchars,
> - sizeof(CharInfoRec));
> + (int) sizeof(CharInfoRec));
> goto BAILOUT;
> }
> ci = calloc(nchars, sizeof(CharInfoRec));
> if (!ci) {
> bdfError("Couldn't allocate pCI (%d*%d)\n", nchars,
> - sizeof(CharInfoRec));
> + (int) sizeof(CharInfoRec));
> goto BAILOUT;
> }
> bitmapFont->metrics = ci;
> @@ -306,7 +306,7 @@ bdfReadCharacters(FontFilePtr file, FontPtr pFont, bdfFileState *pState,
> bitmapExtra->glyphNames = malloc(nchars * sizeof(Atom));
> if (!bitmapExtra->glyphNames) {
> bdfError("Couldn't allocate glyphNames (%d*%d)\n",
> - nchars, sizeof(Atom));
> + nchars, (int) sizeof(Atom));
> goto BAILOUT;
> }
> }
> @@ -314,7 +314,7 @@ bdfReadCharacters(FontFilePtr file, FontPtr pFont, bdfFileState *pState,
> bitmapExtra->sWidths = malloc(nchars * sizeof(int));
> if (!bitmapExtra->sWidths) {
> bdfError("Couldn't allocate sWidth (%d *%d)\n",
> - nchars, sizeof(int));
> + nchars, (int) sizeof(int));
> return FALSE;
> }
> }
> @@ -380,7 +380,7 @@ bdfReadCharacters(FontFilePtr file, FontPtr pFont, bdfFileState *pState,
> bdfEncoding[char_row] = malloc(256 * sizeof(CharInfoPtr));
> if (!bdfEncoding[char_row]) {
> bdfError("Couldn't allocate row %d of encoding (%d*%d)\n",
> - char_row, INDICES, sizeof(CharInfoPtr));
> + char_row, INDICES, (int) sizeof(CharInfoPtr));
> goto BAILOUT;
> }
> for (i = 0; i < 256; i++)
> @@ -490,7 +490,7 @@ bdfReadCharacters(FontFilePtr file, FontPtr pFont, bdfFileState *pState,
> if (!bitmapFont->encoding) {
> bdfError("Couldn't allocate ppCI (%d,%d)\n",
> NUM_SEGMENTS(nencoding),
> - sizeof(CharInfoPtr*));
> + (int) sizeof(CharInfoPtr*));
> goto BAILOUT;
> }
> pFont->info.allExist = TRUE;
> @@ -610,14 +610,14 @@ bdfReadProperties(FontFilePtr file, FontPtr pFont, bdfFileState *pState)
> pFont->info.isStringProp = stringProps;
> if (stringProps == NULL) {
> bdfError("Couldn't allocate stringProps (%d*%d)\n",
> - (nProps + BDF_GENPROPS), sizeof(Bool));
> + (nProps + BDF_GENPROPS), (int) sizeof(Bool));
> goto BAILOUT;
> }
> pFont->info.props = props = calloc(nProps + BDF_GENPROPS,
> sizeof(FontPropRec));
> if (props == NULL) {
> bdfError("Couldn't allocate props (%d*%d)\n", nProps + BDF_GENPROPS,
> - sizeof(FontPropRec));
> + (int) sizeof(FontPropRec));
> goto BAILOUT;
> }
>
> @@ -800,7 +800,8 @@ bdfReadFont(FontPtr pFont, FontFilePtr file,
>
> bitmapFont = calloc(1, sizeof(BitmapFontRec));
> if (!bitmapFont) {
> - bdfError("Couldn't allocate bitmapFontRec (%d)\n", sizeof(BitmapFontRec));
> + bdfError("Couldn't allocate bitmapFontRec (%d)\n",
> + (int) sizeof(BitmapFontRec));
> goto BAILOUT;
> }
>
> @@ -813,7 +814,8 @@ bdfReadFont(FontPtr pFont, FontFilePtr file,
>
> bitmapFont->bitmapExtra = calloc(1, sizeof(BitmapExtraRec));
> if (!bitmapFont->bitmapExtra) {
> - bdfError("Couldn't allocate bitmapExtra (%d)\n", sizeof(BitmapExtraRec));
> + bdfError("Couldn't allocate bitmapExtra (%d)\n",
> + (int) sizeof(BitmapExtraRec));
> goto BAILOUT;
> }
>
> diff --git a/src/bitmap/bdfutils.c b/src/bitmap/bdfutils.c
> index 3a3ee26..288148b 100644
> --- a/src/bitmap/bdfutils.c
> +++ b/src/bitmap/bdfutils.c
> @@ -174,8 +174,9 @@ bdfGetPropertyValue(char *s)
> s++;
> pp = p = malloc((unsigned) strlen(s) + 1);
> if (pp == NULL) {
> - bdfError("Couldn't allocate property value string (%d)\n", strlen(s) + 1);
> - return None;
> + bdfError("Couldn't allocate property value string (%d)\n",
> + (int) strlen(s) + 1);
> + return None;
> }
> while (*s) {
> if (*s == '"') {
> @@ -191,7 +192,7 @@ bdfGetPropertyValue(char *s)
> *p++ = *s++;
> }
> free (pp);
> - bdfError("unterminated quoted string property: %s\n", (pointer) orig_s);
> + bdfError("unterminated quoted string property: %s\n", orig_s);
> return None;
> }
>
> diff --git a/src/bitmap/pcfread.c b/src/bitmap/pcfread.c
> index cf2f696..34eeeb7 100644
> --- a/src/bitmap/pcfread.c
> +++ b/src/bitmap/pcfread.c
> @@ -138,7 +138,8 @@ pcfReadTOC(FontFilePtr file, int *countp)
> }
> tables = malloc(count * sizeof(PCFTableRec));
> if (!tables) {
> - pcfError("pcfReadTOC(): Couldn't allocate tables (%d*%d)\n", count, sizeof(PCFTableRec));
> + pcfError("pcfReadTOC(): Couldn't allocate tables (%d*%d)\n",
> + count, (int) sizeof(PCFTableRec));
> return (PCFTablePtr) NULL;
> }
> for (i = 0; i < count; i++) {
> @@ -262,12 +263,14 @@ pcfGetProperties(FontInfoPtr pFontInfo, FontFilePtr file,
> if (IS_EOF(file)) goto Bail;
> props = malloc(nprops * sizeof(FontPropRec));
> if (!props) {
> - pcfError("pcfGetProperties(): Couldn't allocate props (%d*%d)\n", nprops, sizeof(FontPropRec));
> + pcfError("pcfGetProperties(): Couldn't allocate props (%d*%d)\n",
> + nprops, (int) sizeof(FontPropRec));
> goto Bail;
> }
> isStringProp = malloc(nprops * sizeof(char));
> if (!isStringProp) {
> - pcfError("pcfGetProperties(): Couldn't allocate isStringProp (%d*%d)\n", nprops, sizeof(char));
> + pcfError("pcfGetProperties(): Couldn't allocate isStringProp (%d*%d)\n",
> + nprops, (int) sizeof(char));
> goto Bail;
> }
> for (i = 0; i < nprops; i++) {
> @@ -277,7 +280,7 @@ pcfGetProperties(FontInfoPtr pFontInfo, FontFilePtr file,
> if (props[i].name < 0
> || (isStringProp[i] != 0 && isStringProp[i] != 1)
> || (isStringProp[i] && props[i].value < 0)) {
> - pcfError("pcfGetProperties(): invalid file format %d %d %d\n",
> + pcfError("pcfGetProperties(): invalid file format %ld %d %ld\n",
> props[i].name, isStringProp[i], props[i].value);
> goto Bail;
> }
> @@ -445,7 +448,8 @@ pcfReadFont(FontPtr pFont, FontFilePtr file,
> }
> metrics = malloc(nmetrics * sizeof(CharInfoRec));
> if (!metrics) {
> - pcfError("pcfReadFont(): Couldn't allocate metrics (%d*%d)\n", nmetrics, sizeof(CharInfoRec));
> + pcfError("pcfReadFont(): Couldn't allocate metrics (%d*%d)\n",
> + nmetrics, (int) sizeof(CharInfoRec));
> goto Bail;
> }
> for (i = 0; i < nmetrics; i++)
> @@ -471,7 +475,8 @@ pcfReadFont(FontPtr pFont, FontFilePtr file,
> /* nmetrics is already ok, so nbitmap also is */
> offsets = malloc(nbitmaps * sizeof(CARD32));
> if (!offsets) {
> - pcfError("pcfReadFont(): Couldn't allocate offsets (%d*%d)\n", nbitmaps, sizeof(CARD32));
> + pcfError("pcfReadFont(): Couldn't allocate offsets (%d*%d)\n",
> + nbitmaps, (int) sizeof(CARD32));
> goto Bail;
> }
> for (i = 0; i < nbitmaps; i++) {
> @@ -560,10 +565,11 @@ pcfReadFont(FontPtr pFont, FontFilePtr file,
> goto Bail;
> /* nmetrics already checked */
> ink_metrics = malloc(nink_metrics * sizeof(xCharInfo));
> - if (!ink_metrics) {
> - pcfError("pcfReadFont(): Couldn't allocate ink_metrics (%d*%d)\n", nink_metrics, sizeof(xCharInfo));
> + if (!ink_metrics) {
> + pcfError("pcfReadFont(): Couldn't allocate ink_metrics (%d*%d)\n",
> + nink_metrics, (int) sizeof(xCharInfo));
> goto Bail;
> - }
> + }
> for (i = 0; i < nink_metrics; i++)
> if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT)) {
> if (!pcfGetMetric(file, format, ink_metrics + i))
> @@ -597,7 +603,8 @@ pcfReadFont(FontPtr pFont, FontFilePtr file,
>
> encoding = calloc(NUM_SEGMENTS(nencoding), sizeof(CharInfoPtr*));
> if (!encoding) {
> - pcfError("pcfReadFont(): Couldn't allocate encoding (%d*%d)\n", nencoding, sizeof(CharInfoPtr));
> + pcfError("pcfReadFont(): Couldn't allocate encoding (%d*%d)\n",
> + nencoding, (int) sizeof(CharInfoPtr));
> goto Bail;
> }
>
> @@ -626,7 +633,8 @@ pcfReadFont(FontPtr pFont, FontFilePtr file,
>
> bitmapFont = malloc(sizeof *bitmapFont);
> if (!bitmapFont) {
> - pcfError("pcfReadFont(): Couldn't allocate bitmapFont (%d)\n", sizeof *bitmapFont);
> + pcfError("pcfReadFont(): Couldn't allocate bitmapFont (%d)\n",
> + (int) sizeof *bitmapFont);
> goto Bail;
> }
>
> diff --git a/src/bitmap/pcfwrite.c b/src/bitmap/pcfwrite.c
> index b4abff4..0874c4b 100644
> --- a/src/bitmap/pcfwrite.c
> +++ b/src/bitmap/pcfwrite.c
> @@ -236,7 +236,8 @@ pcfWriteFont(FontPtr pFont, FontFilePtr file)
> }
> offsetProps = malloc(pFont->info.nprops * sizeof(FontPropRec));
> if (!offsetProps) {
> - pcfError("pcfWriteFont(): Couldn't allocate offsetProps (%d*%d)", pFont->info.nprops, sizeof(FontPropRec));
> + pcfError("pcfWriteFont(): Couldn't allocate offsetProps (%d*%d)",
> + pFont->info.nprops, (int) sizeof(FontPropRec));
> return AllocError;
> }
> prop_string_size = 0;
> diff --git a/src/bitmap/snfread.c b/src/bitmap/snfread.c
> index b2b0c67..da362c8 100644
> --- a/src/bitmap/snfread.c
> +++ b/src/bitmap/snfread.c
> @@ -454,12 +454,14 @@ snfReadFontInfo(FontInfoPtr pFontInfo, FontFilePtr file)
>
> pFontInfo->props = malloc(fi.nProps * sizeof(FontPropRec));
> if (!pFontInfo->props) {
> - snfError("snfReadFontInfo(): Couldn't allocate props (%d*%d)\n", fi.nProps, sizeof(FontPropRec));
> + snfError("snfReadFontInfo(): Couldn't allocate props (%d*%d)\n",
> + fi.nProps, (int) sizeof(FontPropRec));
> return AllocError;
> }
> pFontInfo->isStringProp = malloc(fi.nProps * sizeof(char));
> if (!pFontInfo->isStringProp) {
> - snfError("snfReadFontInfo(): Couldn't allocate isStringProp (%d*%d)\n", fi.nProps, sizeof(char));
> + snfError("snfReadFontInfo(): Couldn't allocate isStringProp (%d*%d)\n",
> + fi.nProps, (int) sizeof(char));
> free(pFontInfo->props);
> return AllocError;
> }
> --
> 1.7.3.2
>
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
>
More information about the xorg-devel
mailing list