Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MISRA C++ 2023 rule 7.0.3 "The numerical value of a character shall not be used" #628

Closed
mohammedRafeeque opened this issue Jun 14, 2024 · 4 comments
Assignees
Labels
bug Something isn't working c++ C++ language generator
Milestone

Comments

@mohammedRafeeque
Copy link

Zserio version and language
Zserio: latest from master
Commit date: 6 days ago (6/4/2024 7:12:28 PM)
Commit hash: b8cc6c0

Describe the bug
2 Misra warnings are getting reported for rule MISRACPP2023-7_0_3-a

  1. for (char character : value)
  2. m_buffer.at(m_len) = 0;
<style> </style>
SNo Rule Severity Message Filename Linenumber
1298 MISRACPP2023-7_0_3-a 2 The plain char type shall be initialized only by character values /zserio_runtime/zserio/JsonEncoder.cpp 55
1244 MISRACPP2023-7_0_3-a 2 To the plain char type assign only character values /zserio_runtime/zserio/CppRuntimeException.cpp 42

Please check possibility of fixing the same.

Steps to reproduce the behavior:
SCA run using MISRA 2023 configuration.

Expected behavior
No SCA warnings for MISRA 2023 ruleset

Additional context
N.A

@Roland-Homeier @mikir FYI.

@mohammedRafeeque mohammedRafeeque added the bug Something isn't working label Jun 14, 2024
@mikir mikir added the c++ C++ language generator label Jun 14, 2024
@mikir mikir added this to the 2.15 milestone Jun 14, 2024
@mikir mikir changed the title Fix for MISRA C++ 2023 rule MISRACPP2023-7_0_3-a The plain char type shall be initialized only by character values Fix MISRA C++ 2023 rule 7.0.3 "The numerical value of a character shall not be used" Jun 14, 2024
@Mi-La
Copy link
Contributor

Mi-La commented Aug 9, 2024

We will enable rule S810.

@Mi-La
Copy link
Contributor

Mi-La commented Aug 12, 2024

We don't understand the issue in JsonEncoder.cpp, seems to be almost false positive and moreover the sonar rule is not catching it.
Tried to fix CppRuntimeException by returning '\0' instead of 0.

Some issues were accepted as exceptions - see SonarCloud.

@mohammedRafeeque
Copy link
Author

In latest main we are still getting 19 warning.

Date: 6 days ago (8/13/2024 1:00:38 PM)
Commit hash: 009d16a

<style> </style>
SNo Rule Severity Message Filename Linenumber
1527 MISRACPP2023-7_0_3-a 2 There shall be no conversion from type 'char' to type 'unsigned int' /zserio_runtime/include/roadgraph_reliable/zserio_runtime/zserio/StringConvertUtil.h 48
1526 MISRACPP2023-7_0_3-a 2 There shall be no conversion from type 'char' to type 'int' /zserio_runtime/include/roadgraph_reliable/zserio_runtime/zserio/StringConvertUtil.h 48
1525 MISRACPP2023-7_0_3-a 2 There shall be no conversion from type 'char' to type 'unsigned long' /zserio_runtime/include/roadgraph_reliable/zserio_runtime/zserio/StringConvertUtil.h 48
1524 MISRACPP2023-7_0_3-a 2 There shall be no conversion from type 'unsigned int' to type 'char' /zserio_runtime/include/roadgraph_reliable/zserio_runtime/zserio/StringConvertUtil.h 48
1523 MISRACPP2023-7_0_3-a 2 There shall be no conversion from type 'int' to type 'char' /zserio_runtime/include/roadgraph_reliable/zserio_runtime/zserio/StringConvertUtil.h 48
1522 MISRACPP2023-7_0_3-a 2 There shall be no conversion from type 'unsigned long' to type 'char' /zserio_runtime/include/roadgraph_reliable/zserio_runtime/zserio/StringConvertUtil.h 48
1505 MISRACPP2023-7_0_3-a 2 There shall be no conversion from type 'int' to type 'value_type' /zserio_runtime/include/roadgraph_reliable/zserio_runtime/zserio/StringConvertUtil.h 36
1304 MISRACPP2023-7_0_3-a 2 There shall be no conversion from type 'char' to type 'uint8_t' /zserio_runtime/src/roadgraph_reliable/zserio_runtime/zserio/JsonEncoder.cpp 92
1300 MISRACPP2023-7_0_3-a 2 There shall be no conversion from type 'char' to type 'uint8_t' /zserio_runtime/src/roadgraph_reliable/zserio_runtime/zserio/JsonEncoder.cpp 91
1295 MISRACPP2023-7_0_3-a 2 There shall be no conversion from type 'char' to type 'uint8_t' /zserio_runtime/src/roadgraph_reliable/zserio_runtime/zserio/JsonEncoder.cpp 85
1293 MISRACPP2023-7_0_3-a 2 There shall be no conversion from type 'char' to type 'int' /zserio_runtime/src/roadgraph_reliable/zserio_runtime/zserio/JsonEncoder.cpp 80
1292 MISRACPP2023-7_0_3-a 2 There shall be no conversion from type 'char' to type 'int' /zserio_runtime/src/roadgraph_reliable/zserio_runtime/zserio/JsonEncoder.cpp 76
1291 MISRACPP2023-7_0_3-a 2 There shall be no conversion from type 'char' to type 'int' /zserio_runtime/src/roadgraph_reliable/zserio_runtime/zserio/JsonEncoder.cpp 72
1290 MISRACPP2023-7_0_3-a 2 There shall be no conversion from type 'char' to type 'int' /zserio_runtime/src/roadgraph_reliable/zserio_runtime/zserio/JsonEncoder.cpp 68
1289 MISRACPP2023-7_0_3-a 2 There shall be no conversion from type 'char' to type 'int' /zserio_runtime/src/roadgraph_reliable/zserio_runtime/zserio/JsonEncoder.cpp 64
1288 MISRACPP2023-7_0_3-a 2 There shall be no conversion from type 'char' to type 'int' /zserio_runtime/src/roadgraph_reliable/zserio_runtime/zserio/JsonEncoder.cpp 60
1287 MISRACPP2023-7_0_3-a 2 There shall be no conversion from type 'char' to type 'int' /zserio_runtime/src/roadgraph_reliable/zserio_runtime/zserio/JsonEncoder.cpp 59
1286 MISRACPP2023-7_0_3-a 2 There shall be no conversion from type 'char' to type 'int' /zserio_runtime/src/roadgraph_reliable/zserio_runtime/zserio/JsonEncoder.cpp 57
1172 MISRACPP2023-7_0_3-a 2 There shall be no conversion from type 'char' to type 'uint8_t' /zserio_runtime/src/roadgraph_reliable/zserio_runtime/zserio/BitStreamWriter.cpp 506

@mikir Can you please check.

@mikir
Copy link
Contributor

mikir commented Aug 22, 2024

We have fixed all issues found by SonarCloud rule S810.

@mikir mikir closed this as completed Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working c++ C++ language generator
Projects
None yet
Development

No branches or pull requests

3 participants