Bug 8187 - Some #if nesting issues in lib/replace/snprintf.c
Summary: Some #if nesting issues in lib/replace/snprintf.c
Status: RESOLVED WONTFIX
Alias: None
Product: Samba 3.6
Classification: Unclassified
Component: libsmbclient (show other bugs)
Version: unspecified
Hardware: All All
: P5 minor
Target Milestone: ---
Assignee: Derrell Lipman
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-30 20:26 UTC by Wayne Davison
Modified: 2013-06-02 23:40 UTC (History)
0 users

See Also:


Attachments
Some nested #if changes. (836 bytes, patch)
2011-05-30 20:26 UTC, Wayne Davison
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Wayne Davison 2011-05-30 20:26:09 UTC
Created attachment 6500 [details]
Some nested #if changes.

I was synchronizing the rsync snprintf.c code with samba's version (since I had noticed the lack of some va_end() calls in rsync's version), and I discovered that there are some #ifdef nesting issues in the code.

Note that this code (at line 144) leaves a dangling "#ifndef VA_COPY" open:

#ifndef VA_COPY
#ifdef HAVE_VA_COPY
#define VA_COPY(dest, src) va_copy(dest, src)
#else
#ifdef HAVE___VA_COPY
#define VA_COPY(dest, src) __va_copy(dest, src)
#else
#define VA_COPY(dest, src) (dest) = (src)
#endif
#endif

That section remains open all the way down to line 1194 (after the short vsnprintf() function.  This code is inside the "#if !defined(HAVE_VSNPRINTF) || !defined(HAVE_C99_VSNPRINTF)" section, which would seem to be the ifdef that should actually be matching up with it.  There are three more conditionally-defined functions that follow until an extra #endif on line 1257 finally closes the !HAVE_VSNPRINTF section (snprintf, printf, and fprintf).

So, it's very strange that vsnprintf() won't get defined if VA_COPY is already defined.  To fix this, I moved the #endif from line 1257 up to the VA_COPY section.  However, an alternate fix might be to move the #endif from line 1194 (depending on when you really want snprintf, printf, and fprintf to be defined).

Another issue that turned up:

Right after line 1257 is the vasprintf function, which makes use of the VA_COPY define.  However, on an OS that has is own vsnprintf but does not have vasprintf, the VA_COPY define won't be there (since it was nested inside the vsnprintf section), causing a link error (e.g. Solaris 10 hits this bug).

To fix this latter issue, I moved the start of the vsnprintf #if past the VA_COPY setup.

I haven't tried to compile this in samba, just in rsync (which uses a slightly different file than samba, but is mostly the same).
Comment 1 Wayne Davison 2013-06-02 23:40:04 UTC
Well, if you guys don't care about this, I certainly don't.  Closing.