rspec/rules/S2992/cfamily/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

49 lines
1.3 KiB
Plaintext

== Why is this an issue?
``++typedef++``s are a convenient way of encapsulating complex types in simpler names. However, ``++typedef++``ing a pointer type is problematic because when ``++const++`` is applied to the defined type, it makes the pointer constant, not the pointed-to value. Even when that is what's intended, maintainers may misunderstand.
=== Noncompliant code example
[source,cpp]
----
struct book {
int isbn;
int publishYear;
};
typedef book;
typedef *pBook; // Noncompliant
void mangleBook(const pBook pb) {
pb->isbn = 4; // this is legal; its the pointer, not the book that's const
pb->publishYear=1900;
}
----
=== Exceptions
Function pointers are ignored by this rule.
== Resources
* https://www.securecoding.cert.org/confluence/x/14At[CERT, DCL05-C.] - Use typedefs of non-pointer types only
ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)
=== on 22 Jun 2015, 11:30:55 Ann Campbell wrote:
Why assign this to me?
=== on 22 Jun 2015, 15:21:01 Evgeny Mandrikov wrote:
\[~ann.campbell.2] because counterpart CPP-927 was assigned to you.
=== on 23 Jun 2015, 11:47:20 Ann Campbell wrote:
\[~evgeny.mandrikov] I've added an exception text. I don't see the need to add a code sample to the exception.
endif::env-github,rspecator-view[]