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

Squid Sensor fails to parse files with #define containing "/*" #1903

Closed
Dkapps opened this issue Jul 10, 2020 · 5 comments · Fixed by #1973
Closed

Squid Sensor fails to parse files with #define containing "/*" #1903

Dkapps opened this issue Jul 10, 2020 · 5 comments · Fixed by #1973
Assignees
Labels
Milestone

Comments

@Dkapps
Copy link

Dkapps commented Jul 10, 2020

Description

Squid sensor seems to silently fail parsing c++ files with a #define containing an unmatched "/*".

We found out that one of source files was not correctly analyzed when the line of code counter was set to 0.
After an analysis, Squid seems to choke on one of our #define.

With the original #define (code was obfuscated for project confidentiality issues), the sensor silently fails to analyse

//! This define contains a "/*" 
#define BROKEN_DEFINE " /a/path/*"
19:03:14.688 DEBUG: global settings for: '/home/.../source_file.cpp'
19:03:14.688 DEBUG: Parse 'source_file.cpp' as C++ file
[...]
19:03:15.903 DEBUG: API File: source_file.cpp
19:03:15.903 DEBUG: Header file suffixes: [.hxx, .hpp, .hh, .h]
19:03:15.903 DEBUG: finished preprocessing '/home/.../source_file.cpp'
19:03:15.903 DEBUG: API File: source_file.cpp
19:03:15.903 DEBUG: Header file suffixes: [.h, .hh, .hpp, .H]
19:03:15.915 DEBUG: 'src/dumpprocess/src/source_file.cpp' generated metadata with charset 'UTF-8'
19:03:15.916 DEBUG: Not enough content in 'src/dumpprocess/src/source_file.cpp' to have CPD blocks, it will not be part of the duplication detection
19:03:15.916 DEBUG: CxxFileLinesVisitor: '/home/.../source_file.cpp'
19:03:15.916 DEBUG:    lines:           '540'
19:03:15.916 DEBUG:    executableLines: '[]'
19:03:15.916 DEBUG:    linesOfCode:     '[]'
19:03:15.916 DEBUG:    linesOfComments: '[]'
19:03:15.946 INFO: Sensor C++ (Community) SquidSensor [cxx] (done) | time=2398ms

With a modified #define (but functionnaly identical), the sensor parses the file correctly

//! This define still contains a "/*" , just kind of obfuscated
#define WORKING_DEFINE " /a/path/" "*"
19:04:09.230 DEBUG: global settings for: '/home/.../source_file.cpp'
19:04:09.230 DEBUG: Parse 'source_file.cpp' as C++ file
[...]
19:04:10.455 DEBUG: API File: source_file.cpp
19:04:10.455 DEBUG: Header file suffixes: [.hxx, .hpp, .hh, .h]
19:04:10.455 DEBUG: finished preprocessing '/home/.../source_file.cpp'
19:04:10.455 DEBUG: API File: source_file.cpp
19:04:10.455 DEBUG: Header file suffixes: [.h, .hh, .hpp, .H]
19:04:10.468 DEBUG: 'src/dumpprocess/src/source_file.cpp' generated metadata with charset 'UTF-8'
19:04:10.500 DEBUG: CxxFileLinesVisitor: '/home/.../source_file.cpp'
19:04:10.500 DEBUG:    lines:           '540'
19:04:10.500 DEBUG:    executableLines: '[131, 519, 392, 393, 521, 138, 266, 267, 523, 524, 141, 269, 142, 271, 272, 145, 274, 530, 147, 531, 149, 405, 534, 153, 411, 412, 417, 291, 164, 420, 168, 296, 425, 298, 426, 302, 430, 175, 303, 433, 438, 439, 312, 313, 444, 448, 323, 454, 205, 463, 337, 342, 343, 216, 344, 217, 473, 218, 347, 225, 482, 355, 484, 229, 230, 486, 231, 492, 238, 495, 113, 242, 370, 374, 247, 375, 503, 376, 377, 378, 508, 253, 381]'
19:04:10.500 DEBUG:    linesOfCode:     '[514, 518, 519, 521, 523, 524, 525, 526, 527, 530, 531, 534, 94, 95, 100, 109, 112, 113, 115, 116, 119, 120, 121, 123, 124, 125, 127, 128, 131, 132, 135, 138, 141, 142, 145, 147, 149, 153, 157, 158, 159, 160, 161, 164, 166, 168, 171, 172, 175, 178, 182, 184, 185, 186, 188, 190, 202, 205, 207, 210, 213, 216, 217, 218, 221, 224, 225, 228, 229, 230, 231, 233, 236, 238, 239, 242, 244, 247, 253, 260, 263, 264, 266, 267, 269, 271, 272, 274, 277, 280, 281, 284, 285, 286, 289, 291, 292, 296, 298, 300, 302, 303, 307, 309, 312, 313, 316, 319, 320, 323, 325, 326, 328, 331, 333, 337, 338, 342, 343, 344, 347, 350, 352, 355, 356, 357, 358, 359, 360, 363, 364, 365, 368, 369, 370, 374, 375, 376, 377, 378, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 392, 393, 396, 399, 400, 401, 402, 405, 406, 407, 408, 411, 412, 416, 417, 418, 420, 421, 422, 423, 425, 426, 429, 430, 431, 433, 434, 435, 436, 438, 439, 443, 444, 445, 448, 450, 451, 454, 455, 456, 457, 458, 459, 463, 466, 467, 470, 473, 474, 475, 476, 477, 478, 482, 484, 486, 487, 488, 492, 493, 495, 498, 501, 503, 505, 508, 509, 510, 511]'
19:04:10.500 DEBUG:    linesOfComments: '[1, 516, 517, 262, 279, 24, 27, 283, 30, 288, 33, 36, 294, 39, 295, 42, 45, 48, 51, 54, 310, 311, 57, 60, 318, 63, 66, 322, 324, 69, 72, 330, 75, 332, 78, 335, 336, 81, 84, 340, 341, 87, 90, 346, 91, 92, 349, 351, 354, 105, 106, 362, 107, 111, 367, 373, 118, 122, 380, 130, 134, 137, 395, 140, 398, 144, 404, 152, 415, 163, 167, 170, 428, 174, 177, 180, 181, 441, 442, 447, 192, 193, 194, 195, 196, 197, 453, 198, 199, 201, 204, 461, 462, 209, 212, 469, 215, 472, 220, 223, 480, 481, 227, 490, 235, 491, 241, 500, 246, 507]'
19:04:10.530 INFO: Sensor C++ (Community) SquidSensor [cxx] (done) | time=2547ms

Steps to reproduce the problem

Please provide the steps required to reproduce the problem

  1. Create a source code file containg a macro with a unmatched "/*"

  2. Analyse it with sonar-scanner

Expected behavior

The file should be analysed correctly

Actual behavior

The sensor silently fails to analyse the code

Known workarounds

Declare a global variable instead of a macro, or split the string containing the "/*"

Related information

  • cxx plugin version?
    1.3.1.1807
  • SonarQube version?
    7.9.1.27448
@guwirth guwirth added the bug label Jul 15, 2020
@guwirth guwirth added this to the 1.3.3 milestone Jul 15, 2020
@guwirth
Copy link
Collaborator

guwirth commented Jul 15, 2020

Hi @Dkapps,

Thanks for reporting this. Seems to be a problem with the preprocessor.

Regards,

@guwirth guwirth removed this from the 1.3.3 milestone Jul 15, 2020
@guwirth
Copy link
Collaborator

guwirth commented Jul 15, 2020

@Dkapps maybe you can try it with the SSLR toolkit. Do you get the same error there?

@Dkapps
Copy link
Author

Dkapps commented Jul 15, 2020

@Dkapps maybe you can try it with the SSLR toolkit. Do you get the same error there?

@guwirth I can certainly try, but I don't know how to do it. Can you give me some pointers ?

Regards,

@guwirth
Copy link
Collaborator

guwirth commented Jul 30, 2020

Failing, after /* the preprocessor eats up the rest of the file without error message:

void f1() {}
#define BROKEN_DEFINE " /a/path/*"
void f2() {}

but seems to be no issue with strings, the one below is working:

void f1() { char * txt = " /a/path/*"; }
void f2() {}

Tried it with raw string, also fails:

void f1() {}
#define BROKEN_DEFINE R"( /a/path/*)"
void f2() {}

guwirth added a commit to guwirth/sonar-cxx that referenced this issue Nov 3, 2020
- better support special cases like:
```C++
#define A B/**/C
#define A "/**/"
#define A B // comment
```
- minor refactoring
- close SonarOpenCommunity#1903
@guwirth guwirth self-assigned this Nov 3, 2020
@guwirth guwirth added this to the 2.0.0 milestone Nov 3, 2020
@guwirth
Copy link
Collaborator

guwirth commented Nov 4, 2020

@Dkapps it's fixed and you can try it (but only with 2.0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants