[PATCH 1/2] regedit: Overhaul Unicode line processing

Hugh McMaster hugh.mcmaster at outlook.com
Mon Nov 21 18:01:44 CST 2016


On Tuesday, 22 November 2016 6:38 AM, Alexandre Julliard wrote:
> Hugh McMaster writes:
> 
> > +        p = strpbrkW(line, line_endings);
> > +        if (!p)
> > +        {
> > +            HeapFree(GetProcessHeap(), 0, buf);
> > +            return NULL;
> 
> If there are no line endings you need to read more data instead of
> failing.

By the time p == NULL, we are already at the end of the buffer.
And even if we weren't, the buffer would be increased and more data
read in, on the second (and subsequent) loops.

This does assume, of course, that the .reg file format is valid. I'm not
sure if .reg files are valid if they end without a newline sequence.
I'll look into this and write some tests to check.

> Also it looks to me that you are reading the entire file into
> the buffer instead of just one line.

The patch splits the buffer contents into lines. But we do end up
reading the entire file into the buffer because 
REG_VAL_BUF_SIZE is set to 4096 bytes. We could decrease
this to 1024 bytes if you want. But, in many cases, I expect
the same behaviour to occur.

Still, I'm not entirely sure how to implement what you're suggesting
with line-by-line reads.

We can't use fgets because \r line endings are valid on Windows.

I suppose we could use fread like it was fgetc, and read character by
character until we reach a line ending. But that defeats the purpose
of using fread to read in large chunks.

Hugh


More information about the wine-devel mailing list