Samba 2.2.2 problem in lib/sprintf.c

Martin Pool mbp at samba.org
Thu Nov 29 23:42:03 GMT 2001


On 27 Nov 2001, "John E. Malmberg" <wb8tyw at qsl.net> wrote:

> An optimizing C compiler, especially on a RISC platform has intimate 
> knowledge of the standard library routines, and will attempt to 
> eliminate procedure calls where ever possible.  If you are supplying 
> your own routines, their definition can not exist in a header file that 
> is #included for the module.  That breaks things.

Almost every compiler that plays this kind of trick has a command-line
option that disables them.  For example, on gcc it is -fno-builtin.
So perhaps you just need to set that, or better yet contribute a
configure.in test that detects the problem and sets it into CFLAGS.

On the other hand, if the compiler's so good then I'd hope that the
sprintf() is properly compliant with the ANSI C99 standard.  The test
for that in ./configure on samba_2_2 is currently

#include <sys/types.h>
#include <stdarg.h>
void foo(const char *format, ...) { 
       va_list ap;
       int len;
       char buf[5];

       va_start(ap, format);
       len = vsnprintf(0, 0, format, ap);
       va_end(ap);
       if (len != 5) exit(1);

       if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(1);

       exit(0);
}
main() { foo("hello"); }

It would be interesting to see the result of this on your compiler.

Also, if there is something in <stdio.h> that invokes the magic
behaviour, then perhaps you should try adding it to the test code in
configure.in.  

However if the intrinsic version works and the library version is
broken then we have a nasty situation, because I think the compiler
will sometimes fall back to a library call for complex cases.  So then
we come back to needing the equivalent of -fno-builtin.

-- 
Martin 




More information about the samba-technical mailing list