Thread (1 message) 1 message, 1 author, 2015-03-27

Re: "man 3 vsprintf" : simple bug in EXAMPLE section

From: Zhen Ren <hidden>
Date: 2015-03-27 09:52:09

Hi Michael,

I'm so sorry for this negative report.

Yeah, you're right. It'll fall through,loop again,do "vsprintf" and return if done.

--
Best regards,
Eric, Ren
HA team, SUSE

quoted
quoted
Hello Zhen Ren, 
 
On 27 March 2015 at 06:27, Zhen Ren [off-list ref] wrote: 
quoted
Hi, 
There is simple bug in EXAMPLE section of "man 3 vsprintf". 

Function will return nothing if  it steps into the last "else {}". 

------------------ example code ----------------- 
 char * 
       make_message(const char *fmt, ...) 
       { 
           int n; 
           int size = 100;     /* Guess we need no more than 100 bytes */ 
           char *p, *np; 
           va_list ap; 
. 
.cut off 
. 
               np = realloc(p, size); 
               if (np == NULL) { 
                   free(p); 
                   return NULL; 
               } else { 
                   p = np; 
+                return p; 
               } 
           } 
       } 
 
I have not looked too closely at the code, but the above report 
appears incorrect to me. The function should NOT be returning at that 
point. It should be falling through and then round the loop once more. 
If I've missed something, could you elaborate a little more on the 
problem, please? 
 
Cheers, 
 
Michael 
 
 

--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help