13.07.2015 Views

TASKING VX-toolset for ARM User Guide

TASKING VX-toolset for ARM User Guide

TASKING VX-toolset for ARM User Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CERT C Secure Coding Standard19.6. Arrays (ARR)ARR01-CARR34-CARR35-CDo not apply the sizeof operator to a pointer when taking the size of an arrayA function parameter declared as an array, is converted to a pointer by the compiler.There<strong>for</strong>e,the sizeof operator applied to this parameter yields the size of a pointer, and not the size ofan array.Ensure that array types in expressions are compatibleUsing two or more incompatible arrays in an expression results in undefined behavior.Do not allow loops to iterate beyond the end of an arrayReading or writing of data outside the bounds of an array may lead to incorrect programbehavior or execution of arbitrary code.19.7. Characters and Strings (STR)STR30-CSTR33-CSTR34-CSTR36-CDo not attempt to modify string literalsWriting to a string literal has undefined behavior, as identical strings may be shared and/orallocated in read-only memory.Size wide character strings correctlyWide character strings may be improperly sized when they are mistaken <strong>for</strong> narrow stringsor <strong>for</strong> multi-byte character strings.Cast characters to unsigned types be<strong>for</strong>e converting to larger integer sizesA signed character is sign-extended to a larger signed integer value. Use an explicit cast, orcast the value to an unsigned type first, to avoid unexpected sign-extension.Do not specify the bound of a character array initialized with a string literalThe compiler issues this warning when the character buffer initialized by a string literal doesnot provide enough room <strong>for</strong> the terminating null character.19.8. Memory Management (MEM)MEM00-CAllocate and free memory in the same module, at the same level of abstractionMEM08-CThe compiler issues this warning when the result of the call to malloc(), calloc() or realloc()is discarded, and there<strong>for</strong>e not free()d, resulting in a memory leak.Use realloc() only to resize dynamically allocated arraysOnly use realloc() to resize an array. Do not use it to trans<strong>for</strong>m an object to an object of adifferent type.859

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!