Fix issue when reading path lists
ClosedPublic

Authored by apol on Jul 16 2018, 3:54 PM.

Details

Summary

They were not being split properly.

Test Plan

Tests pass, including the new one.

Diff Detail

Repository
R237 KConfig
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
apol created this revision.Jul 16 2018, 3:54 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptJul 16 2018, 3:54 PM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald Transcript
apol requested review of this revision.Jul 16 2018, 3:54 PM
anthonyfieroni added inline comments.
src/core/kconfiggroup.cpp
176 ↗(On Diff #37886)

It should be

p < data.size() && data[p] == '\\'

or you will access not owned memory. Better is to cache data.size() in variable then to use it everywhere.

dfaure requested changes to this revision.Aug 6 2018, 12:01 PM
dfaure added a subscriber: dfaure.
dfaure added inline comments.
autotests/kconfigtest.cpp
524–526

You broke the "no EOL" testcase.
Please add yours before it.

src/core/kconfiggroup.cpp
163 ↗(On Diff #37886)

I don't understand why this needs a vector. Isn't this only about consecutive backslashes?
Wouldn't a counter be enough?

src/core/kconfigini.cpp
797

Did you mean '\,' here?

This revision now requires changes to proceed.Aug 6 2018, 12:01 PM
apol marked 3 inline comments as done.Aug 6 2018, 12:10 PM
apol added inline comments.
src/core/kconfiggroup.cpp
163 ↗(On Diff #37886)

We're extracting the whole string and then removing the escapes, we need to remember them all.

apol updated this revision to Diff 39182.Aug 6 2018, 12:10 PM

Addressed issues by David and Anthony

I don't really understand why we can't just skip the escapes as we go along, as most parsers do, for the sake of efficiency. This is already a state-machine based parser so it should be easy to integrate that in, no?

apol added a comment.Aug 7 2018, 1:02 PM

I don't really understand why we can't just skip the escapes as we go along, as most parsers do, for the sake of efficiency. This is already a state-machine based parser so it should be easy to integrate that in, no?

You mean we could integrate it in KConfigIni itself?
Currently values are always stored as QString, it would need a refactoring to allow to store values in different types.

dfaure requested changes to this revision.Aug 8 2018, 7:43 AM

No, I don't think I mean that.

The code in kconfiggroup is already iterating over one character at a time and handling escapes and .... wait, what are we fixing here exactly?
I applied your patch, reverted kconfiggroup.cpp, and the new unittest still passes.

PASS : KConfigTest::testPath()

Could it be that your change in kconfigini.cpp is enough to fix the bug?

(Otherwise it means the unittest isn't comprehensive enough)

This revision now requires changes to proceed.Aug 8 2018, 7:43 AM
apol added a comment.Aug 8 2018, 10:11 AM

Correct, I wanted to fix all the allocations as the commit message says, then I realised it wasn't even working well when I added the unit test, so I fixed that too.

The problem with the allocation is that it's allocating for the remaining part of the field and freeing again the rest every time we read each element of the list. This showed up in heaptrack for Discover.

Can we split this into two commits then? The bugfix (which certainly seems fine to me), and the optimization (which is separate and needs to be measured for increased CPU usage, and alternative solutions like QStringRef).

apol updated this revision to Diff 42504.Sep 28 2018, 4:51 PM

Removed optimisation

apol retitled this revision from Figure out the escaped path list on kconfig to Fix issue when reading path lists.Sep 28 2018, 4:51 PM
apol edited the summary of this revision. (Show Details)
apol edited the test plan for this revision. (Show Details)
dfaure accepted this revision.Sep 28 2018, 4:57 PM
This revision is now accepted and ready to land.Sep 28 2018, 4:57 PM
This revision was automatically updated to reflect the committed changes.