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, Feb 24, 2011 at 11:31:35AM +0000, Iain Hibbert wrote:

The original code seems to be:

>               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,
> #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 */
> #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",
> #endif
>                       sl->isl_pkts[0], sl->isl_bytes[0],
>                       sl->isl_pkts[1], sl->isl_bytes[1],
>                       sl->isl_pkts[2], sl->isl_bytes[2],
>                       sl->isl_pkts[3], sl->isl_bytes[3]);
>  
>               t += strlen(t);

That is just trully horrid and should be converted to snprintf().
The chance of the buffer being big enough seesm unlikely to be
guaranteeable!

        David

-- 
David Laight: david%l8s.co.uk@localhost


Home | Main Index | Thread Index | Old Index