tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: macro directives inside macro arguments undefined



On Thu, 24 Feb 2011, Christos Zoulas wrote:
> >The patch attached fixes building this with pcc (for which the behaviour
> >is to error out with a syntax error), by moving the directives away from
> >the arguments, any objections to commit?
>
> I don't like this patch much. I think it is better to do:
>
>       static const char fmt[] = .....;
>
>       sprintf(str, fmt, ...

like the attached?  (I'm not sure its any better :)

On Thu, 24 Feb 2011, David Laight wrote:
> That is just trully horrid and should be converted to snprintf().
> The chance of the buffer being big enough seesm unlikely to be
> guaranteeable!

Well, I agree that snprintf() would have been better, though:

- the output line buffer is 2048 bytes

- fixing all the sprint->snprint in IPF would be a lot of work

- this is external sources and I'm not sure if its worth diverging from
  upstream (we don't have the latest version installed, in any case)

- does IPF have a future? (I don't mean to diss it, I understand the main
  developer is now employed by a company that is not open-source friendly)

- is NPF intended to (eventually) replace IPF in base?

iain
Index: ipmon.c
===================================================================
RCS file: /cvsroot/src/dist/ipf/tools/ipmon.c,v
retrieving revision 1.16
diff -u -r1.16 ipmon.c
--- ipmon.c     19 Aug 2009 08:35:32 -0000      1.16
+++ ipmon.c     24 Feb 2011 14:48:58 -0000
@@ -904,19 +904,28 @@
                t += strlen(t);
        }
        if (sl->isl_type != ISL_NEW) {
-               sprintf(t,
 #ifdef USE_QUAD_T
 #ifdef PRId64
-                       " Forward: Pkts in %" PRId64 " Bytes in %" PRId64
-                       " Pkts out %" PRId64 " Bytes out %" PRId64
-                       " Backward: Pkts in %" PRId64 " Bytes in %" PRId64
-                       " Pkts out %" PRId64 " Bytes out %" PRId64,
+       static const char fmt[] =
+           " Forward: Pkts in %" PRId64 " Bytes in %" PRId64
+           " Pkts out %" PRId64 " Bytes out %" PRId64
+           " Backward: Pkts in %" PRId64 " Bytes in %" PRId64
+           " Pkts out %" PRId64 " Bytes out %" PRId64;
 #else
-                       " Forward: Pkts in %qd Bytes in %qd Pkts out %qd Bytes 
out %qd Backward: Pkts in %qd Bytes in %qd Pkts out %qd Bytes out %qd",
-#endif /* PRId64 */
+       static const char fmt[] =
+           " Forward: Pkts in %qd Bytes in %qd"
+           " Pkts out %qd Bytes out %qd"
+           " Backward: Pkts in %qd Bytes in %qd"
+           " Pkts out %qd Bytes out %qd";
+#endif
 #else
-                       " Forward: Pkts in %ld Bytes in %ld Pkts out %ld Bytes 
out %ld Backward: Pkts in %ld Bytes in %ld Pkts out %ld Bytes out %ld",
+       static const char fmt[] =
+           " Forward: Pkts in %ld Bytes in %ld"
+           " Pkts out %ld Bytes out %ld"
+           " Backward: Pkts in %ld Bytes in %ld"
+           " Pkts out %ld Bytes out %ld";
 #endif
+               sprintf(t, fmt,
                        sl->isl_pkts[0], sl->isl_bytes[0],
                        sl->isl_pkts[1], sl->isl_bytes[1],
                        sl->isl_pkts[2], sl->isl_bytes[2],


Home | Main Index | Thread Index | Old Index