kernel32: fix PROFILE_Load to handle mac line endings

Michael Karcher wine at mkarcher.dialup.fu-berlin.de
Sun Sep 14 08:58:57 CDT 2008


Am Sonntag, den 14.09.2008, 14:48 +0200 schrieb Erik Inge Bolsø:
> Fixes bug 15281. With testcase.
> @@ -407,6 +407,7 @@ static PROFILESECTION *PROFILE_Load(HANDLE hFile, ENCODING * pEncoding)
>      {
>          szLineStart = next_line;
>          next_line = memchrW(szLineStart, '\n', szEnd - szLineStart);
> +        if (!next_line) next_line = memchrW(szLineStart, '\r', szEnd - szLineStart);
>          if (!next_line) next_line = szEnd;
>          else next_line++;
>          szLineEnd = next_line;

This fails on files with mixed line endings. Alas, there is no mempbrk
or memcspn to help you scanning for both endings at the same time.

> @@ -415,7 +416,7 @@ static PROFILESECTION *PROFILE_Load(HANDLE hFile, ENCODING * pEncoding)
>  
>          /* get rid of white space */
>          while (szLineStart < szLineEnd && PROFILE_isspaceW(*szLineStart)) szLineStart++;
> -        while ((szLineEnd > szLineStart) && ((szLineEnd[-1] == '\n') || PROFILE_isspaceW(szLineEnd[-1]))) szLineEnd--;
> +        while ((szLineEnd > szLineStart) && ((szLineEnd[-1] == '\n') || (szLineEnd[-1] == '\r') || PROFILE_isspaceW(szLineEnd[-1]))) szLineEnd--;
>  
>          if (szLineStart >= szLineEnd) continue;

This hunk is unneded. PROFILE_isspaceW already checks for \n and \r. The
already present check for '\n' could be removed, but that should be a
separate patch. I will send it (together with a cleanup in
PROFILE_isspaceW) after testing.
 

> @@ -694,6 +694,273 @@ static void test_GetPrivateProfileString(void)
>      DeleteFileA(filename);
>  }
>  
> +/* as above, but cr-only terminated lines */
> +static void test_cr(void)
> +{

[...]
Wouldn't it be sensible to factor out the common testing code, and just
pass the string that gets written to the file as parameter? (I didn't
check line-by-line that it matches, but the comment seems to implicate
it.) If you refactor, you could also add a test that uses mixed endings
(some \r, some \n, some \r\n).

Regards,
  Michael Karcher




More information about the wine-devel mailing list