rspec/rules/S1234/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

39 lines
1.0 KiB
Plaintext

== Why is this an issue?
Any class that has memory to manage should provide all the methods necessary to properly manage that memory, including a copy constructor and an override of ``++operator=++``. Without those methods, you're likely to end up with memory leaks and multiple class instances pointing at the same segments of memory for their members.
=== Noncompliant code example
[source,cpp]
----
class MyClass // Noncompliant
{
private:
char* cpData;
public
MyClass(const char* value);
~MyClass();
}
MyClass a = new MyClass("The quick red fox");
MyClass b = new MyClass("How now brown cow");
b = a; // cpData pointer, not value copied. Also b's old value not deleted: Memory leak.
----
== Resources
* https://www.securecoding.cert.org/confluence/x/SAAV[CERT, OOP-06-CPP.] - Create a private copy constructor and assignment operator for non copyable objects
ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)
=== duplicates: S3624
endif::env-github,rspecator-view[]