This commit is contained in:
Nilstrieb 2022-07-27 20:42:58 +00:00
parent 52edb5c934
commit f95c82ece5
4 changed files with 4 additions and 4 deletions

View file

@ -146,7 +146,7 @@
<h1 id="conventions"><a class="header" href="#conventions">Conventions</a></h1>
<p>General conventions that C code should obey.</p>
<h2 id="memory-allocation"><a class="header" href="#memory-allocation">Memory allocation</a></h2>
<p>Always check the return value of <code>malloc</code>. If it is a null pointer, derefence it to immediately abort the processas as we cannot reasonable recover from OOM in most cases. If such a recovery is possible, recover instead. On some platforms, dereferencing a null pointer does <em>not</em> abort the process. In these cases, the null pointer is a perfectly fine pointer, and just continue using it instead. Note that this derefence should usually be a volatile operation as the compiler would optimize it away otherwise. I have reported upstream issues on compilers about this, but they have not yet answered.</p>
<p>Always check the return value of <code>malloc</code>. If it is a null pointer, dereference it to immediately abort the processas as we cannot reasonable recover from OOM in most cases. If such a recovery is possible, recover instead. On some platforms, dereferencing a null pointer does <em>not</em> abort the process. In these cases, the null pointer is a perfectly fine pointer, and just continue using it instead. Note that this derefence should usually be a volatile operation as the compiler would optimize it away otherwise. I have reported upstream issues on compilers about this, but they have not yet answered.</p>
<p>If the pointer is non-null, <code>free</code> it directly after the <code>malloc</code> call. This prevents memory leaks of all sorts. Afterwards,
you can use it freely in your program.</p>
<h2 id="includes"><a class="header" href="#includes">Includes</a></h2>

View file

@ -174,7 +174,7 @@ body cannot fit into a single line, make a new function instead.</p>
<div style="break-before: page; page-break-before: always;"></div><h1 id="conventions"><a class="header" href="#conventions">Conventions</a></h1>
<p>General conventions that C code should obey.</p>
<h2 id="memory-allocation"><a class="header" href="#memory-allocation">Memory allocation</a></h2>
<p>Always check the return value of <code>malloc</code>. If it is a null pointer, derefence it to immediately abort the processas as we cannot reasonable recover from OOM in most cases. If such a recovery is possible, recover instead. On some platforms, dereferencing a null pointer does <em>not</em> abort the process. In these cases, the null pointer is a perfectly fine pointer, and just continue using it instead. Note that this derefence should usually be a volatile operation as the compiler would optimize it away otherwise. I have reported upstream issues on compilers about this, but they have not yet answered.</p>
<p>Always check the return value of <code>malloc</code>. If it is a null pointer, dereference it to immediately abort the processas as we cannot reasonable recover from OOM in most cases. If such a recovery is possible, recover instead. On some platforms, dereferencing a null pointer does <em>not</em> abort the process. In these cases, the null pointer is a perfectly fine pointer, and just continue using it instead. Note that this derefence should usually be a volatile operation as the compiler would optimize it away otherwise. I have reported upstream issues on compilers about this, but they have not yet answered.</p>
<p>If the pointer is non-null, <code>free</code> it directly after the <code>malloc</code> call. This prevents memory leaks of all sorts. Afterwards,
you can use it freely in your program.</p>
<h2 id="includes"><a class="header" href="#includes">Includes</a></h2>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long