Skip to contentSkip to conversation

msdos_format_name() bug?

DISCUSSION Roel Kluin 2 participants 2 messages Feb 2, 2009

lore
Share & tools
lore

Roel Kluin

author
#0 lore raw

in msdos_format_name(const unsigned char *name, int len, ...)

name is the proposed name, len is its length.

        while (c != '.' && len--)
                c = *name++;
        if (c == '.') {
                while (walk - res < 8)
                        *walk++ = ' ';
                while (len > 0 && walk - res < MSDOS_NAME) {

Is the postfix decrement in the first loop correct, or should it be prefix? (isn't that one character too many?)

If not, note that if the proposed name ends with a dot: e.g. 'myfile.' the first while loop iterates until the dot which ends the loop, but because of the postfix decrement len already is 0, so the third while loop won't start. Is that correct?

Roel

#1 lore raw
Quoted 11 lines · Roel Kluin

in msdos_format_name(const unsigned char *name, int len, ...)

name is the proposed name, len is its length.

        while (c != '.' && len--)
                c = *name++;
        if (c == '.') {
                while (walk - res < 8)
                        *walk++ = ' ';
                while (len > 0 && walk - res < MSDOS_NAME) {
Quoted 7 lines

Is the postfix decrement in the first loop correct, or should it be prefix? (isn't that one character too many?)

If not, note that if the proposed name ends with a dot: e.g. 'myfile.' the first while loop iterates until the dot which ends the loop, but because of the postfix decrement len already is 0, so the third while loop won't start. Is that correct?

In the "myfile." case, it seems correct. It will provide "MYFILE ".

Signature · 1 line
OGAWA Hirofumi <[email protected]>