mate-desktop / pluma

A powerful text editor for MATE
http://www.mate-desktop.org
GNU General Public License v2.0
157 stars 65 forks source link

pluma-document: avoid garbarge value in 'file_with_bom' function #500

Closed sc0w closed 5 years ago

sc0w commented 5 years ago

Fixes clang analyzer warning:

pluma-document.c:682:14: warning: The left operand of '==' is a garbage value
        if ((bom[0] == '\357') &&
             ~~~~~~ ^

In the tests, make sure you can't reproduce the issue https://github.com/mate-desktop/pluma/issues/301

raveit65 commented 5 years ago

No idea, if this is the right fix for it, but it seems the warning is gone.

cwendling commented 5 years ago

A possibly more interesting test is a file with less than 3 bytes, maybe even just for fun:

$ echo -ne '\xEF\xBB' > file.utf8
$ file file.utf8
file.utf8: ISO-8859 text, with no line terminators
$ pluma file.utf8

Possibly one out of many times it would think the file has a BOM.