Bug 502458

Summary: crash in qstring-comparison-to-implicit-char
Product: [Developer tools] clazy Reporter: marcel
Component: generalAssignee: Alexander Lohnau <alexander.lohnau>
Status: RESOLVED FIXED    
Severity: crash CC: alexander.lohnau, marcel, smartins
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description marcel 2025-04-05 16:04:49 UTC
SUMMARY


STEPS TO REPRODUCE
1. create a minimal project
main.cpp
~~~~
#include <QByteArray>
#include <QString>

int main() {
    QByteArray ba = "this is a qbytearray";
    if ((ba == QStringLiteral("windows_generic_MSG")))
    {
        return 1;
    }

    return 0;
}
~~~~
and this CMakeLists.txt
~~~~
cmake_minimum_required(VERSION 3.29)
project(clazyerror)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(CMAKE_EXPORT_COMPILE_COMMANDS)
    set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
endif()
set(CMAKE_CXX_STANDARD 17)
find_package(Qt5Core REQUIRED)

add_executable(clazyerror main.cpp)
target_link_libraries(clazyerror Qt5::Core)
~~~


2. 
3. 

OBSERVED RESULT


EXPECTED RESULT


SOFTWARE/OS VERSIONS
Windows: 
macOS: 
(available in the Info Center app, or by running `kinfo` in a terminal window)
Linux/KDE Plasma: 
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: qt5-base 5.15.16+kde+r130-4 ( archlinux)

ADDITIONAL INFORMATION
Stack trace:
<unknown> 0x00007fffea4a5624
QStringComparisonToImplicitChar::VisitStmt qstring-comparison-to-implicit-char.cpp:45
ClazyASTConsumer::VisitStmt Clazy.cpp:149
ClazyASTConsumer::HandleTranslationUnit Clazy.cpp:168
main ClazyStandaloneMain.cpp:216


First commit with this crash: 
commit 215b2ca9e187d638d153bbeccdab8bf82f536e2b
Author: Alexander Lohnau <alexander.lohnau@gmx.de>
Date:   Mon Dec 23 10:31:20 2024 +0100

    Optimize more codepaths to use operator enum instead of string comparisons
    
    This is a small optimization, but checking the operator costs 1/10 of the time of a string comparison.
    Especially for the often used Utils and level0 check, this is sensible
    to have.

 LLVM (version: 19.1.7)
Comment 1 Alexander Lohnau 2025-06-04 14:35:14 UTC
Oh! Can Reproduce....
Comment 2 Bug Janitor Service 2025-06-04 14:54:27 UTC
A possibly relevant merge request was started @ https://invent.kde.org/sdk/clazy/-/merge_requests/188
Comment 3 gruenich (Christoph GrĂ¼ninger) 2025-06-05 16:15:34 UTC
Git commit f8403541415040b0e9e9ca290eebcb9ed5a62be8 by Christoph GrĂ¼ninger, on behalf of Alexander Lohnau.
Committed on 05/06/2025 at 16:13.
Pushed by gruninger into branch 'master'.

Fix crash in qstring-comparison-to-implicit-char

M  +1    -0    Changelog
M  +1    -1    src/checks/level0/qstring-comparison-to-implicit-char.cpp
M  +7    -0    tests/qstring-comparison-to-implicit-char/main.cpp

https://invent.kde.org/sdk/clazy/-/commit/f8403541415040b0e9e9ca290eebcb9ed5a62be8