Skip to content

Conversation

@matzeschmid
Copy link
Contributor

…ences less than 3 octal digits and hexadecimal escape sequences less than 2 hexadecimal digits (ticket #9370).

Add end of sequence check for single quoted sequences.
Add compliant and non-compliant test cases for short escape sequences.

…ences less than 3 octal digits and hexadecimal escape sequences less than 2 hexadecimal digits (ticket #9370).

Add end of sequence check for single quoted sequences.
Add compliant and non-compliant test cases for short escape sequences.
@matzeschmid
Copy link
Contributor Author

Based on the discussion of development thread started by Richard Smith i created the changes for this pull request.
Versat opened a ticket for this (#9370).
Discussion thread: https://sourceforge.net/p/cppcheck/discussion/development/thread/7274ed3842/

@matzeschmid matzeschmid reopened this Sep 24, 2019
@matzeschmid
Copy link
Contributor Author

I just saw that there is another pull request #2216 with a fix for ticket #9370.
And it really looks much better than my fix.
It's not just a fix, it's a complete refactoring of MISRA 4.1 rule checker, clear structure, much easier to read and understand.

@jubnzv
Copy link
Contributor

jubnzv commented Sep 25, 2019

I see some problems with parsing expressions that contains 2+ digits, e.g. following examples will cause FP:

int c41_12         = '\12323';
int c41_13         = '\1232\3';

@matzeschmid
Copy link
Contributor Author

Based on discussion on #2216 i checked the fix against the following code and got the expected result. I agree, some of the checks should be added to test file.

int c41_12        = '\12323';  // 4.1
int c41_13        = '\1232\3'; // 4.1

void misra_4_1()
{
    (void)printf("\x41g");         // 4.1
    (void)printf("\x8g");          // 4.1
    (void)printf("\x41\x42");
    (void)printf("\x41" "g");
    (void)printf("%i", '\141t');   // 4.1
    (void)printf("%i", '\141\t');
    (void)printf("%i", '\141');
    (void)printf("%i", '\0t');     // 4.1
    (void)printf("%i", '\0\t');
    (void)printf("%i", '\0');
    (void)printf("%i", '\12t');    // 4.1
    (void)printf("%i", '\12\t');
    (void)printf("%i", '\12');
    (void)printf("%i", '\12323');  // 4.1
    (void)printf("%i", '\1232\3'); // 4.1
}

Add non-assignment test cases for MISRA rule 4.1.
@matzeschmid
Copy link
Contributor Author

Checked fix against strings which contains simple escape sequences (especially \\) which should not lead to MISRA 4.1 false positive. Passed, got expected result.

Test lines:

const char *s41_9 = "hello\\world\n";
(void)printf("hello\\world\r\n");

@danmar
Copy link
Owner

danmar commented Sep 28, 2019

I merged the other PR... please update this now.

@matzeschmid
Copy link
Contributor Author

I merged the other PR... please update this now.

OK, fine.
So i just close my PR to remove it from the list, right ?

@danmar
Copy link
Owner

danmar commented Oct 1, 2019

ok.

@danmar danmar closed this Oct 1, 2019
@danmar
Copy link
Owner

danmar commented Oct 1, 2019

thanks for your work. if you think the other pr should be tweaked somehow let me know.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants