On Sunday 24 February 2008 14:34:17 walter harms wrote:
> 
> >>>   /* maximum as in procps 3.2.7 */
> >>>   period =  xatou_range(str, 1, 999999999);
> >>>   argv += optind;
> >>>
> >> -1 causes an error 'invalid number'
> > 
> > And 0?
> > 
> >> and 999999999/(3600*24*365)=31  but 2036 (when time() ends :) - 2008 = 28 
> >> so no need to worry about
> >> if someone likes to type long number he likes to wait long time also.
> > 
> > Maybe reducing the limit could be an idea?
> > period =  xatou_range(str, 1, 3600*24*365);
> > 
> 
> any upper limit is artificial, so why not say: "The user wants to 30 Years so 
> lets wait"
> the 0 causes some flicker :) i don not think it is important to fix, it does 
> not crash or
> cause any serious harm.
> 
> 
> >>>   header=xasprintf("Every %ds: %-*s", period, width, cmd);
> >>>
> >> i tought that also but any window resize will cause problems. These days i 
> >> often use minicom/xterm to monitor and discover i have
> >> a much to small window .....
> > 
> > I see...in that case it would be better to free header every time as it 
> > leaks memory. 
> > 
> 
> so far i know asprint() should do an realloc if the pointer is not NULL. 
> (correct me if i am wrong)
> So i had to free after leaving the endless loop.
> 
> 
> re,
>  wh
> 

Hi,
xasprintf doesn't take a pointer like v/asprintf

int asprintf(char **strp, const char *fmt, ...);
int vasprintf(char **strp, const char *fmt, va_list ap);
char *xasprintf(const char *format, ...)

and it seems to me that the returned string 
is malloced at every call again and again. 

// Die with an error message if we can't malloc() enough space and do an
// sprintf() into that space.
char *xasprintf(const char *format, ...)
{
        va_list p;
        int r;
        char *string_ptr;

#if 1
        // GNU extension
        va_start(p, format);
        r = vasprintf(&string_ptr, format, p);
        va_end(p);
#else
        // Bloat for systems that haven't got the GNU extension.
        va_start(p, format);
        r = vsnprintf(NULL, 0, format, p);
        va_end(p);
        string_ptr = xmalloc(r+1);
        va_start(p, format);
        r = vsnprintf(string_ptr, r+1, format, p);
        va_end(p);
#endif

        if (r < 0)
                bb_error_msg_and_die(bb_msg_memory_exhausted);
        return string_ptr;
}

Ciao,
Tito
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to