[RFC] cmd: Add a space at the end of the first echo'ed batch line [try5]

Dmitry Timoshkov dmitry at codeweavers.com
Mon Nov 1 10:40:33 CDT 2010


GOUJON Alexandre <ale.goujon at gmail.com> wrote:

> On 11/01/2010 03:12 PM, Vitaliy Margolen wrote:
> >> +    static const char escaped_space[] = "@space@";
> >> +    DWORD len_space = strlen(escaped_space);
> > The better way to calculate size of a static string, which is a 
> > compile time calculation. strlen() call is a runtime.
> The better way is ... ?
> In compare_line(), sizeof(space_cmd) is used but I guess 
> sizeof(space_cmd/space_cmd[0]) is more portable, isn't it ?
> I thought strlen() was optimized in that case because used with a const 
> string.

Only if you expect that a compiler knows what strlen() is. Better to not rely
on internal compiler knowledge.

> >> +static char* replace_escaped_spaces(const char *data, DWORD size, 
> >> DWORD *new_size)
> >> +    char *a, *b, *new_data;
> >> +    a = b = (char*)data;
> > a, b should be "const char*" as well.
> Unfortunately, I can't do that : strncpy and HeapFree complains about 
> const strings.

In general never cast away const. I don't see where you are using 'a' or 'b'
in strncpy() or HeapFree() as a target pointer that prevents making them const,
only 'new_data' needs to be non-const.

> +        a = b += len_space;

This is absolutely unreadable.

Also if you could add some spaces around '+'/'-'/'=' in the cases below it would improve
readability as well:

> +    *new_size=0;

> +        strncpy(new_data+*new_size, a, b-a+1);
> +        *new_size += b-a +1;
> +        new_data[*new_size-1] = ' ';

> +    strncpy(new_data+*new_size, a, strlen(a)+1);

etc.

-- 
Dmitry.



More information about the wine-devel mailing list