G'day,

Previously, the compiler complained long and loud about dynamic strings
being used as format specifiers in the PPTX driver (cd/src/drv/pptx.c).

When I first reported this, I noted that the warnings could be stopped
by adding a const, e.g. changing:

        const char *pPPTXItem = "This is not a pipe!";

to:

        const char * const pPPTXItem = "This is not a pipe!";

The warnings have been addressed, but via a different approach:  The
fprintf calls for strings without any format specifiers have been
changed from:

        fprintf(pFile, pPPTXItem);

to:

        fprintf(pFile, "%s", pPPTXItem);

Where there was one or more parameters to a (f)printf call, there were
no warnings that were detected/reported by my build + summary tools.

However, gcc 6.4.x (under Gentoo) does generate more warnings, in a
variety of areas (the summary totals over 1300 lines at present!)
This post will only look at the "extra const" case above.

The benefit of static, rather than dynamic, format strings is that
modern compilers can do static checking on the sanity/coherence of
the format directives versus the supplied arguments.  In the case of
pptx.c, three minor cases of extra arguments were identified with
gcc 5.4.x on the Mint system, once "const" was added:


        too many arguments for format [-Wformat-extra-args]:
            drv/pptx.c:993:[Function:pptxHatchLine]:
              };
            drv/pptx.c:1059:[Function:pptxEndLine]:
              };
            drv/pptx.c:1074:[Function:pptxEndLine]:
              };


The attached file contains the patch that adds the "const" qualifier
to the problem cases.  (Originally I added "const" almost everywhere,
but have stripped it down here, for the sake of brevity.)

cheers,

s-b etc
programmer, Grouse Software
Index: src/drv/pptx.c
===================================================================
--- src/drv/pptx.c	(revision 747)
+++ src/drv/pptx.c	(working copy)
@@ -976,7 +976,7 @@
   int alphaPct = (int)(((double)alpha / 255.) * 100 * 1000);
   int bAlphaPct = (int)(((double)bAlpha / 255.) * 100 * 1000);
 
-  const char *patt =
+  const char * const patt =
   {/*012345678901234| - path style ident (15) */
     "               <a:pattFill prst=\"%s\">\n"
     "                  <a:fgClr>\n"
@@ -1048,7 +1048,7 @@
   int i;
   int alphaPct = (int)(((double)alpha / 255.) * 100 * 1000);
 
-  const char *lineEndPrefix =
+  const char * const lineEndPrefix =
   {/*012345678901234| - path style ident (15) */
     "               <a:ln cap=\"flat\" cmpd=\"sng\" w=\"%d\">\n"  /* to be closed (lineEndSuffix) */
     "                  <a:solidFill>\n"
@@ -1063,7 +1063,7 @@
     "                  <a:prstDash val = \"%s\"/>\n"
   };
 
-  const char *lineEndSuffix =
+  const char * const lineEndSuffix =
   {/*012345678| - primitives ident (9) */
     "                  <a:round/>\n"
     "                  <a:headEnd len=\"lg\" w=\"lg\" type=\"none\"/>\n"
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Iup-users mailing list
Iup-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/iup-users

Reply via email to