HomeContentsContents

strutil.c: strfmt()

Priority: Very High

There is a bug in the strfmt() function in strutil.c that results in the Genesis driver getting caught up in an infinite loop if an empty pad is provided in the format argument to the ColdC strfmt() method (for example, '%4{}s').

In strutil.c find the following block of code in the function strfmt():


        /* get the pad char */
        if (*s == '{') {
            Int    x = 0;

            s++;
            for (; *s && *s != '}'; s++) {
                if (s[0] == '\\' && (s[1] == '\\' || s[1] == '}'))
                    s++;
                fill[x++] = *s;
            }
            fill[x] = (char) NULL;
            s++;
        } else {
            fill[0] = ' ';
            fill[1] = (char) NULL;
        }
    

And replace it with:

        
        /* get the pad char */
        if (*s == '{') {
            Int    x = 0;

            s++;
            for (; *s && *s != '}'; s++) {
                if (s[0] == '\\' && (s[1] == '\\' || s[1] == '}'))
                    s++;
                fill[x++] = *s;
            }
            if (!x) {
                fill[0] = ' ';
                fill[1] = (char) NULL;
            } else {
                fill[x] = (char) NULL;
            }
            s++;
        } else {
            fill[0] = ' ';
            fill[1] = (char) NULL;
        }
    
Top

Contents Previous Next Functions

Valid XHTML 1.0 Strict