Avoid an asan runtime error
ClosedPublic

Authored by jtamate on Mar 7 2018, 3:35 PM.

Details

Summary

Initialize the arrays to the maximum size of the enums and use c++11 initialization to ensure that all values are set to zero (or equivalent).

Test Plan

execute kdialog --getexistingdirectory smb://

before the patch, the following messages from gcc asan are displayed:

kdesrc/frameworks/kiconthemes/src/kiconeffect.cpp:170:51: runtime error: index 3 out of bounds for type 'int [3]'
kdesrc/frameworks/kiconthemes/src/kiconeffect.cpp:172:51: runtime error: index 3 out of bounds for type 'float [3]'
kdesrc/frameworks/kiconthemes/src/kiconeffect.cpp:174:40: runtime error: index 3 out of bounds for type 'bool [3]'
kdesrc/frameworks/kiconthemes/src/kiconeffect.cpp:176:35: runtime error: index 3 out of bounds for type 'int [3]'
kdesrc/frameworks/kiconthemes/src/kiconeffect.cpp:176:74: runtime error: index 3 out of bounds for type 'int [3]'
kdesrc/frameworks/kiconthemes/src/kiconeffect.cpp:180:35: runtime error: index 3 out of bounds for type 'int [3]'

This runtime error is not shown any more.

Diff Detail

Repository
R302 KIconThemes
Lint
Lint Skipped
Unit
Unit Tests Skipped
jtamate created this revision.Mar 7 2018, 3:35 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptMar 7 2018, 3:35 PM
jtamate requested review of this revision.Mar 7 2018, 3:35 PM
anthonyfieroni added inline comments.
src/kiconeffect.cpp
44–49

You can use {{}} to all

jtamate updated this revision to Diff 28946.Mar 7 2018, 3:45 PM

Cleaner initialization, thanks anthonyfieroni.

apol added a subscriber: apol.Mar 7 2018, 4:31 PM
apol added inline comments.
src/kiconeffect.cpp
44

To what does this initialize the array?

jtamate added inline comments.Mar 8 2018, 7:31 AM
src/kiconeffect.cpp
44

effect: 0
value: 0
color: QColor(Invalid)
trans: false
key: ""
color2: QColor(Invalid)

jtamate updated this revision to Diff 28991.Mar 8 2018, 8:56 AM

with spaces after : and ,

mwolff accepted this revision.Mar 8 2018, 9:16 AM
mwolff added a subscriber: mwolff.
mwolff added inline comments.
src/kiconeffect.cpp
44

it may be a good idea to add a comment that links to http://en.cppreference.com/w/cpp/language/zero_initialization to clarify what's happening here

This revision is now accepted and ready to land.Mar 8 2018, 9:16 AM
jtamate updated this revision to Diff 29002.Mar 8 2018, 11:48 AM

Added the link.

mwolff added a comment.Mar 8 2018, 4:01 PM

still accepted, fell free to submit

This revision was automatically updated to reflect the committed changes.