Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





  Rule 21.6 and snprintf()
Posted by: dejanpan - 05-04-2018, 03:01 AM - Forum: General Questions - Replies (4)

We are using snprintf() function (https://linux.die.net/man/3/snprintf) in a framework that lets you program autonomous driving cars (our product).
The function is currently being used only for logging of console data on the secondary, non-real time computer.


However, both PCLint and Coverity static code analysis tools mark it as non-compliant:

Rule 21.6
The Standard Library input/output functions shall not be used
C90 [Unspecified 2–5, 16–18; Undefined 77–89; Implementation 53–68]
C99 [Unspecified 3–6, 34–37; Undefined 138–166, 186; Implementation J.3.12(14–32)] [Koenig 74]

Category: Required
Analysis: Decidable, Single Translation Unit
Applies to: C90, C99

Amplification
This rule applies to the functions that are specified as being provided by and, in C99,
their wide-character equivalents specified in Sections 7.24.2 and 7.24.3 of the C99 Standard as being
provided by .

None of these identifiers shall be used and no macro with one of these names shall be expanded.

Rationale
Streams and file I/O have unspecified, undefined and implementation-defined behaviours associated
with them.

See also
Rule 22.1, Rule 22.3, Rule 22.4, Rule 22.5, Rule 22. 6



We have a following rebuttal:
The problem is that if the source and destination string buffers in a snprintf() call are the same, the behavior is undefined.

These buffers are passed as char pointers to

Code:
snprintf()
. Checking that two pointer variables can never be the same in a program (in all possible executions) is called alias analysis. It is a static code analysis that static code analysis tools can do, but it usually is imprecise (can have false positives). So it is easier for them to ban the use of
Code:
snprintf()
altogether.

We claim that we can use snprintf() ONLY IF we ALWAYS check that the source and destination buffers are NOT the same before calling snprintf().

Code:
if source != destination:
  snprintf(...)
else:
  raise error

Pardon pseudo code but if I use actual C code it won't let me post this question.

Additionally, based on the rule's Rationale text it could be argued that the snprintf() call is OK since it's not a stream or file output call.

I would love to hear some thoughts from MISRA members.

Print this item

  Dir 4.10: Is a different form of the include guard considered a violation of the directive?
Posted by: GerlindeKettl - 29-03-2018, 12:36 PM - Forum: 7.4 Code design - Replies (1)

The example of Directive 4.10 "Precautions shall be taken in order to prevent the contents of a header file being included more than once" says that in order to facilitate checking, the contents of the header should be protected from being included more than once using one of the following two forms:

Code:
#if !defined ( identifier )
#define identifier
/* Contents of file */
#endif



#ifndef identifier
#define identifier
/* Contents of file */
#endif
I got software from a third party which uses the first form, but the parentheses are a bit differently placed:

Code:
#if ( !defined identifier )
As I consider this include guard correct from a functional point of view, is this nevertheless a violation of Dir 4.10 because it does not use one of the two forms listed in the example?

Print this item

  Dir 4.8 If no pointer is declared but implementation is visible
Posted by: cxlin - 29-03-2018, 11:11 AM - Forum: 7.4 Code design - Replies (1)

For Dir 4.8 the document is not clear about whether the following case should be considered as non-compliant.

/* def.h */
struct SomeType
{
/* Object implementation */
}

/* no-use.c */
#include def.h
/* Do something. But no use of SomeType at all. */

The example doesn't involve any pointer but indeed goes against the rationale since the implementation details of SomeType is not needed in no-use.c and it should at least be opaque. Also, logically, "no pointer" implies "a pointer is never dereferenced", since there is no such pointer to begin with.

Please kindly help to advise. Thanks!

Print this item

  Rule 13.2 Compliance
Posted by: rcseacord - 21-03-2018, 06:51 PM - Forum: 8.13 Side effects - Replies (2)

Does the following expression comply with Rule 13.2?

(x = a) && (x = b)

What if it is preceded by the following declaration?

int a = 0;

Thanks,
rCs

Print this item

  News on future releases
Posted by: pdrudi - 15-03-2018, 02:32 PM - Forum: MISRA AC SLSF discussions - Replies (1)

Hi,
will MISRA AC SLSF guideline be updated?
If yes, is there a planned release date?

Thank you in advance,
Paolo Drudi

Print this item

  Rule 20.2
Posted by: kalpak - 08-03-2018, 03:06 PM - Forum: 8.20 Preprocessing directives - Replies (2)

Why is
#include "c:\headers\measurement_regs.h "
non compliant to rule 20.2 due to \ in the path?

Print this item

  model information blocks in virtual subsystems (rule 022)
Posted by: ben.call - 06-03-2018, 06:55 PM - Forum: MISRA AC SLSF discussions - Replies (1)

MISRA AC SLSF 022 states that a model information block is required for every subsystem. Does application of this rule include virtual subsystems, or only "true" (i.e., atomic or nonvirtual) subsystems?
Stated differently: Virtual subsystems should share the identity and origin of the parent model, atomic subsystem, or library to which they belong (the rationale for rule 022), so do they need that information reiterated in their own model information block?
I would appreciate knowing what the community consensus is on this topic.
~Ben

Print this item

  Copyright
Posted by: ankitshah413 - 05-03-2018, 09:47 AM - Forum: MISRA-C:2004 Exemplar Suite - Replies (1)

Hello,

I have one question regarding the copyright of the Exemplar Suite. I want to share this with my colleagues in my company, so am i allowed to do that?

We have an internal tool for sharing , can i upload these examples there?

It will be accessed in my company only.

Thank you.

Print this item

  Rule 5.2 : confusion
Posted by: ankitshah413 - 01-03-2018, 04:08 PM - Forum: 6.5 Identifiers - Replies (2)

Hello,

I am getting MISRA 5.2 rule violation in my project. The code for which i am getting violation is a structure that is declared as extern in one header file. The code example is as under

1.h

Code:
extern struct con tmp_ev;

2.c
Code:
struct con tmp_ev;
cioF_get(&tmp_ev);

3.c
Code:
struct con tmp_ev;
(void)eeF_read(CON, &tmp_ev);

I get the warning only in 2.c in the line struct con tmp_ev; saying that declaration of symbol tmp_ev hides symbol tmp_ev and not in 3.c . Both 2.c and 3.c include the 1.h header file.

I am confused why this issue is present. Can anyone help me resolve this issue?

Thank you

Print this item

  Rule 8.3 Function definition
Posted by: ankitshah413 - 21-02-2018, 10:12 AM - Forum: 6.8 Declarations and Definitions - Replies (1)

I want to just clarify that following is a MISRA violation before using it in my code. I am calling one function from a file as under:

Code:
(void)Dem_SetEventStatus((Dem_EventIdType)(dtcFlt_t.dtc[dtcIndex]), DEM_EVENT_STATUS_FAILED);

Here Dem_SetEventStatus is defined in one header as under:

Code:
extern FUNC(Std_ReturnType, RTE_CODE) Dem_SetEventStatus (Dem_ASR42_EventIdType EventId, Dem_ASR42_EventStatusType EventStatus);

Here Dem_EventIdType is a typedef of unit8 and Dem_ASR42_EventIdType is unsigned short.

So , there were the violation of MISRA 8.3 right??

Print this item

Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,173
» Latest member: SnakeLeon
» Forum threads: 998
» Forum posts: 2,752

Full Statistics

Online Users
There are currently 249 online users.
» 0 Member(s) | 247 Guest(s)
Bing, Google

Latest Threads
Rule 6.2.1: non-inline co...
Forum: 4.6 Basic concepts
Last Post: cgpzs
22-11-2024, 10:11 AM
» Replies: 0
» Views: 42
Rule 0.1.2
Forum: 4.0 Language independent issues
Last Post: stephanmuench
21-11-2024, 01:12 PM
» Replies: 0
» Views: 55
A18-9-4
Forum: AUTOSAR C++:2014 rules
Last Post: cgpzs
23-10-2024, 12:04 PM
» Replies: 2
» Views: 405
A8-4-5: are partial moves...
Forum: AUTOSAR C++:2014 rules
Last Post: misra cpp
22-10-2024, 02:03 PM
» Replies: 1
» Views: 342
model information blocks ...
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
22-10-2024, 01:27 PM
» Replies: 1
» Views: 4,463
MISRA AL SLSF - Rule 043I
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
22-10-2024, 01:11 PM
» Replies: 1
» Views: 8,878
MISRA AC EC guidelines
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 08:21 AM
» Replies: 4
» Views: 15,533
News on future releases
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 08:05 AM
» Replies: 1
» Views: 5,709
Signal naming convention ...
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 07:57 AM
» Replies: 1
» Views: 7,265
Rule 7.0.2: operator cons...
Forum: 4.7 Standard conversions
Last Post: karos
14-10-2024, 08:52 PM
» Replies: 2
» Views: 458