todo.txt 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  1. Some source code rules to keep eye on when programming and testing
  2. Most are closed-source non-free products but for example psv-studio can be used free for this.
  3. Few of these tools can be used at low-costs for not much money to pay for a license.
  4. rosecheckers has unmaintained software on sourceforge but last commit is from year 2021.
  5. which should check for cert standards and that has it own
  6. site with text or xml file available for download. It also generates dot graph data!
  7. This tool is called rosebud and available at rosecheckers on sourceforge
  8. This info can also be used with the Linux kernel sparse checker software
  9. Rule 1.1 MISRA-C2012-1.1 The program shall contain no violations of the standard C syntax and constraints, and shall not exceed the implementation’s translation limits.
  10. Rule 1.2 MISRA-C2012-1.2 Language extensions should not be used
  11. Rule 1.3 MISRA-C2012-1.3 There shall be no occurrence of undefined or critical unspecified behaviour
  12. Rule 2.1 MISRA-C2012-2.1 A project shall not contain unreachable code
  13. Rule 2.2 MISRA-C2012-2.2 There shall be no dead code
  14. Rule 2.3 MISRA-C2012-2.3 A project should not contain unused type declarations
  15. Rule 2.4 MISRA-C2012-2.4 A project should not contain unused tag declarations
  16. Rule 2.5 MISRA-C2012-2.5 A project should not contain unused macro declarations
  17. Rule 2.6 MISRA-C2012-2.6 A function should not contain unused label declarations
  18. Rule 2.7 MISRA-C2012-2.7 There should be no unused parameters in functions
  19. Rule 3.1 MISRA-C2012-3.1 The character sequences /* an // shall not be used within a comment
  20. Rule 3.2 MISRA-C2012-3.2 If the source line containing a // comment ends with a \ character in the source character set, the next line becomes part of the comment. This may result in unintentional removal of code.
  21. Rule 4.1 MISRA-C2012-4.1 Octal and hexadecimal escape sequences shall be terminated
  22. Rule 4.2 MISRA-C2012-4.2 Trigraphs should not be used
  23. Rule 5.1 MISRA-C2012-5.1 External identifiers shall be distinct
  24. Rule 5.2 MISRA-C2012-5.2 Identifiers declared in the same scope and name space shall be distinct
  25. Rule 5.3 MISRA-C2012-5.3 An identifier declared in an inner scope shall not hide an identifier declared in an outer scope
  26. Rule 5.4 MISRA-C2012-5.4 Macro identifiers shall be distinct
  27. Rule 5.5 MISRA-C2012-5.5 Identifiers shall be distinct from macro names
  28. Rule 5.6 MISRA-C2012-5.6 A typedef name shall be a unique identifier
  29. Rule 5.7 MISRA-C2012-5.7 A tag name shall be a unique identifier
  30. Rule 5.8 MISRA-C2012-5.8 Identifiers that define objects or functions with external linkage shall be unique
  31. Rule 5.9 MISRA-C2012-5.9 Identifiers that define objects or functions with internal linkage should be unique
  32. Rule 6.1 MISRA_C2012-6.1 Bit-fields shall only be declared with an appropriate type
  33. Rule 6.2 MISRA-C2012-6.2 Single-bit named bit fields shall not be of a signed type
  34. Rule 7.1 MISRA-C2012-7.1 Octal constants shall not be used
  35. Rule 7.2 MISRA_C2012-7.2 A “u” or “U” suffix shall be applied to all integer constants that are represented in an unsigned type
  36. Rule 7.3 MISRA-C2012-7.3 The lowercase character “l” shall not be used in a literal suffix
  37. Rule 7.4 MISRA-C2012-7.4 A string literal shall not be assigned to an object unless the object's type is pointer to const-qualified char
  38. Rule 8.1 MISRA-C2012-8.1 Types shall be explicitly specified
  39. Rule 8.2 MISRA-C2012-8.2 Function types shall be in prototype form with named parameters
  40. Rule 8.3 MISRA-C2012-8.3 All declarations of an object or function shall use the same names and type qualifiers
  41. Rule 8.4 MISRA-C2012-8.4 A compatible declaration shall be visible when an object or function with external linkage is defined
  42. Rule 8.5 MISRA-C2012-8.5 An external object or function shall be declared once in one and only one file
  43. Rule 8.6 MISRA-C2012-8.6 An identifier with external linkage shall have exactly one external definition
  44. Rule 8.7 MISRA-C2012-8.7 Functions and objects should not be defined with external linkage if they are referenced in only one translation unit
  45. Rule 8.8 MISRA-C2012-8.8 The static storage class specifier shall be used in all declarations of objects and functions that have internal linkage
  46. Rule 8.9 MISRA-C2012-8.9 An object should be defined at block scope if its identifier only appears in a single function
  47. Rule 8.10 MISRA-C2012-8.10 An inline function shall be declared with the static storage class
  48. Rule 8.11 MISRA-C2012-8.11 When an array with external linkage is declared, its size should be explicitly specified
  49. Rule 8.12 MISRA-C2012-8.12 Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique
  50. Rule 8.13 MISRA-C2012-8.13 A pointer should point to a const-qualified type whenever possible
  51. Rule 8.14 MiSRA-C2012-8.14 The restrict type qualifi er shall not be used
  52. Rule 9.1 MISRA-C2012-9.1 The value of an object with automatic storage duration shall not be read before it has been set
  53. Rule 9.2 MISRA-C2012-9.2 The initializer for an aggregate or union shall be enclosed in braces
  54. Rule 9.3 MISRA-C2012-9.3 Arrays shall not be partially initialized
  55. Rule 9.4 MISRA-C2012-9.4 An element of an object shall not be in itialized more than once
  56. Rule 9.5 MISRA-C2012-9.5 Where designated initializers are used t o initialize an array object the size of the array shall be specified explicitly
  57. Rule 10.1 MISRA-C2012-10.1 Operands shall not be of an inappropriate essential type
  58. Rule 10.2 MISRA-C2012-10.2 Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations
  59. Rule 10.3 MISRA-C2012-10.3 The value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category
  60. Rule 10.4 MISRA-C2012-10.4 Both operands of an operator in which the usual arithmetic conversions are performed s hall have the same essential type category
  61. Rule 10.5 MISRA_C2012-10.5 The value of an expression should not be cast to an inappropriate essential type
  62. Rule 10.6 MISRA-C2012-10.6 The value of a composite expression shall not be assigned to an object with wider essential type
  63. Rule 10.7 MISRA-C2012-10.7 If a composite expression is used as one operand of an operator in which the usual arithmetic conversions are performed then the other operand shall not have wider essential type
  64. Rule 10.8 MISRA-C2012-10.8 The value of a composite expression shall not be cast to a different essential type category or a wider essential type
  65. Rule 11.1 MISRA-C2012-11.1 Conversions shall not be performed between a pointer to a function and any other type
  66. Rule 11.2 MISRA-C2012-11.2 Conversions shall not be performed between a pointer to an incomplete type and any other type
  67. Rule 11.3 MISRA-C2012-11.3 A cast shall not be performed between a pointer to object type and a pointer to a diff erent object type
  68. Rule 11.4 MISRA-C2012-11.4 A conversion should not be performed between a pointer to object and an integer type
  69. Rule 11.5 MISRA-C2012-11.5 A conversion should not be performed from pointer to void into pointer to object
  70. Rule 11.6 MISRA-C2012-11.6 A cast shall not be performed between pointer to void and an arithmetic type
  71. Rule 11.7 MISRA-C2012-11.7 A cast shall not be performed between pointer to object and a noninteger arithmetic type
  72. Rule 11.8 MISRA-C2012-11.8 A cast shall not remove any const or volatile qualification from the type pointed to by a pointer
  73. Rule 11.9 MISRA-C2012-11.9 The macro NULL shall be the only per mitted form of integer null pointer constant
  74. Rule 12.1 MiSRA-C2012-12.1 The precedence of operators within expressions should be made explicit
  75. Rule 12.2 MISRA-C2012-12.2 The right hand operand of a shift operator shall lie in the range zero to one less than the width in bits of the essential type of the left hand operand
  76. Rule 12.3 MISRA-C2012-12.3 The comma operator should not be used
  77. Rule 12.4 MISRA-C2012-12.4 Evaluation of constant expressions should not lead to unsigned integer wrap-around
  78. Rule 13.1 MISRA-C2012-13.1 Initializer lists shall not contain persistent side eff ects
  79. Rule 13.2 MISRA-C2012-13.2 The value of an expression and its persistent side eff ects shall be the same under all permitted evaluation orders
  80. Rule 13.3 MISRA-C2012-13.3 A full expression containing an increment (++) or decrement (--) operator should hav e no other potential side eff ects other than that caused by the increment or decrement operator
  81. Rule 13.4 MISRA-C2012-13.4 The result of an assignment operator should not be used
  82. Rule 13.5 MISRA-C2012-13.5 The right hand operand of a logical && or || operator shall not contain persistent side effects
  83. Rule 13.6 MISRA-C2012-13.6 The operand of the sizeof operator shall not contain any expression which has potential side effects
  84. Rule 14.1 MISRA-C2012-14.1 A loop counter shall not have essentially fl oating type
  85. Rule 14.2 MISRA-C2012-14.2 A for loop shall be well-formed
  86. Rule 14.3 MISRA-C2012-14.3 Controlling expressions shall not be invariant
  87. Rule 14.4 MISRA-C2012-14.4 The controlling expression of an if statement and the controlling expression of an iteration- statement shall have essentially Boolean type
  88. Rule 15.1 MISRA-C2012-15.1 The goto statement should not be used
  89. Rule 15.2 MISRA-C2012-15.2 The goto statement shall jump to a label declared later in the same function
  90. Rule 15.3 MISRA-C2012-15.3 Any label referenced by a goto statement shall be declared in the same block, or in any block enclosing the goto statement
  91. Rule 15.4 MISRA-C2012-15.4 There should be no more than one break or goto statement used to terminate any iteration statement
  92. Rule 15.5 MISRA-C2012-15.5 A function should have a single point of exit at the end
  93. Rule 15.6 MISRA-C2012-15.6 The body of an iteration-statement or a selection-statement shall be a compound-statement
  94. Rule 15.7 MISRA-C2012-15.7 All if … else if constructs shall be terminated with an else statement
  95. Rule 16.1 MISRA-C2012-16.1 All switch statements shall be well-formed
  96. Rule 16.2 MISRA-C2012-16.2 A switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statement
  97. Rule 16.3 MISRA-C2012-16.3 An unconditional break statement shall terminate every switch-clause
  98. Rule 16.4 MISRA-C2012-16.4 Every switch statement shall have a default label
  99. Rule 16.5 MISRA-C2012-16.5 A default label shall appear as either the first or the last switch label of a switch statement
  100. Rule 16.6 MISRA-C2012-16.6 Every switch statement shall have at least two switch-clauses
  101. Rule 16.7 MISRA-C2012-16.7 A switch-expression shall not have essentially Boolean type
  102. Rule 17.1 MISRA-C2012-17.1 The features of shall not be used
  103. Rule 17.2 MISRA-C2012-17.2 Functions shall not call themselves, either directly or indirectly
  104. Rule 17.3 MISRA-C2012-17.3 A function shall not be declared implicitly
  105. Rule 17.4 MISRA-C2012-17.4 All exit paths from a function with non-void return type shall have an explicit return statement with an expression
  106. Rule 17.5 MISRA-C2012-17.5 The function argument corresponding to a parameter declared to have an array type shall have an appropriate number of elements
  107. Rule 17.6 MISRA-C2012-17.6 The declaration of an array parameter shall not contain the static keyword between the [ ]
  108. Rule 17.7 MISRA-C2012-17.7 The value returned by a function having non-void return type shall be used
  109. Rule 17.8 MISRA-C2012-17.8 A function parameter should not be modifi ed
  110. Rule 18.1 MISRA-C2012-18.1 A pointer resulting from arithmetic on a pointer operand shall address an element of the same array as that pointer operand
  111. Rule 18.3 MISRA-C2012-18.3 The relational operators >, >=, < and <= shall not be applied to objects of pointer type except where they point into the same object
  112. Rule 18.4 MISRA-C2012-18.4 The +, -, += and -= operators should not be applied to an expression of pointer type
  113. Rule 18.5 MISRA-C2012-18.5 Declarations should contain no more than two levels of pointer nesting
  114. Rule 18.6 MISRA-C2012-18.6 The address of an object with automatic storage shall not be copied to another object that persists after the first object has ceased to exist
  115. Rule 18.7 MISRA-C2012-18.7 Flexible array members shall not be declared
  116. Rule 18.8 MISRA-C2012-18.8 Variable-length array types shall not be used
  117. Rule 19.2 MiSRA-C2012-19.2 The union keyword should not be used
  118. Rule 20.1 MISRA-C2012-20.1 #include directives should only be preceded by preprocessor directives or comments
  119. Rule 20.2 MISRA-C2012-20.2 The ', " or \ characters and the /* or // character sequences shall not occur in a header file name
  120. Rule 20.3 MISRA-C2012-20.3 The #include directive shall be followed by either a or "filename" sequence
  121. Rule 20.4 MISRA-C2012-20.4 A macro shall not be defined with the same name as a keyword
  122. Rule 20.5 MISRA-C2012-20.5 #undef should not be used
  123. Rule 20.6 MISRA-C2012-20.6 Tokens that look like a preprocessing directive shall not occur within a macro argument
  124. Rule 20.7 MISRA-C2012-20.7 Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses
  125. Rule 20.8 MISRA-C2012-20.8 The controlling expression of a #if or #elif preprocessing directive shall evaluate to 0 or 1
  126. Rule 20.9 MISRA-C2012-20.9 All identifiers used in the controlling expression of #if or #elif preprocessing directives shall be #defi ne’d before evaluation
  127. Rule 20.10 MISRA-C2012-21.10 The # and ## preprocessor operators should not be used
  128. Rule 20.11 Misra-c2012-21.11 A macro parameter immediately following a # operator shall not immediately be followed by a ## operator
  129. Rule 20.12 MISRA-C2012-21.12 A macro parameter used as an operand to the # or ## o perators, which is itself subj ect to further macro replacement, shall only be used as an operand to these operators
  130. Rule 20.13 MISRA-C2012-20.13 A line whose first token is # shall be a valid preprocessing directive
  131. Rule 20.14 MISRA-C2012-20.14 All #else, #elif and #endif preprocessor directives shall reside in the same file as the #if, #ifdef or #ifndef directive to which they are related
  132. Rule 21.1 MISRA-C2012-21.1 #defi ne and #undef shall not be used on a reserved identifier or reserved macro name
  133. Rule 21.2 MISRA-C2012-21.2 A reserved identifier or macro name shall not be declared
  134. Rule 21.3 MISRA-C2012-21.3 The memory allocation and deallocation functions of shall not be used
  135. Rule 21.4 MISRA-C2012-21.4 The standard header file shall not be used
  136. Rule 21.5 MISRA-C2012-21.5 The standard header file shall not be used
  137. Rule 21.6 MISRA-C2012-21.6 The Standard Library input/output functions shall not be used
  138. Rule 21.7 MISRA-C2012-21.7 The atof, atoi, atol and atoll functions of shall not be used
  139. Rule 21.8 MISRA-C2012-21.8 The library functions abort, exit, getenv and system of shall not be used
  140. Rule 21.9 MISRA-C2012-21.9 The library functions bsearch and qsort of shall not be used
  141. Rule 21.10 MISRA-C2012-21.10 The Standard Library time and date functions shall not be used
  142. Rule 21.11 MISRA-C2012-21.11 The standard header file shall not be used
  143. Rule 21.12 MISRA-C2012-21.12 The exception handling features of should not be used
  144. Rule 22.1 MISRA-C2012-22.1 All resources obtained dynamically by means of Standard Library functions shall be explicitly released
  145. Rule 22.2 MISRA-C2012-22.2 A block of memory shall only be freed if it was allocated by means of a Standard Library function
  146. Rule 22.4 MISRA-C2012-22.4 There shall be no attempt to write to a stream which has been opened as read-only
  147. Rule 22.5 MISRA-C2012-22.5 A pointer to a FILE object shall not be dereferenced
  148. Rule 22.6 MISRA-C2012-22.6 The value of a pointer to a FILE shall not be used after the associated stream has been closed
  149. 1 CWE-910 : The software uses or accesses a file descriptor after it has been closed.
  150. 2 CWE-415: The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.
  151. 3 CWE-404: The program does not release or incorrectly releases a resource before it is made available for re-use.
  152. 4 CWE-401: The software does not sufficiently track and release allocated memory after it has been used, which slowly consumes remaining memory.
  153. 5 CWE-369: The product divides a value by zero.
  154. 6 CWE-252: The software does not check the return value from a method or function, which can prevent it from detecting unexpected states and conditions.
  155. 7 CWE-783: The program uses an expression in which operator precedence causes incorrect logic to be used.
  156. 8 CWE-561: The software contains dead code, which can never be executed.
  157. 9 CWE-484 : The program omits a break statement within a switch or similar construct, causing code associated with multiple conditions to execute. This can cause problems when the programmer only intended to execute code associated with one condition.
  158. 10 CWE-478: The code does not have a default case in a switch statement, which might lead to complex logical errors and resultant weaknesses.
  159. 11 CWE-338: The product uses a Pseudo-Random Number Generator (PRNG) in a security context, but the PRNG's algorithm is not cryptographically strong.
  160. 12 CWE-121: Stack-based Buffer Overflow
  161. 13 CWE-122: Heap-based Buffer Overflow
  162. 14 CWE-124: Buffer Underwrite ('Buffer Underflow')
  163. 15 CWE-126: Buffer Over-read
  164. 16 CWE-127: Buffer Under-read
  165. 17 CWE-197: Numeric Truncation Error
  166. 18 CWE-242: Use of Inherently Dangerous Function
  167. 19 CWE-398: Indicator of Poor Code Quality
  168. 20 CWE-401: Improper Release of Memory Before Removing Last Reference ('Memory Leak')
  169. 21 CWE-416: Use After Free
  170. 22 CWE-457: Use of Uninitialized Variable
  171. 23 CWE-476: NULL Pointer Dereference
  172. 24 CWE-483: Incorrect Block Delimitation
  173. 25 CWE-562: Return of Stack Variable Address
  174. 26 CWE-563: Assignment to Variable without Use ('Unused Variable')
  175. 27 CWE-570: Expression is Always False
  176. 28 CWE-571: Expression is Always True
  177. 29 CWE-674: Uncontrolled Recursion
  178. 30 CWE-758: Reliance on Undefined, Unspecified, or Implementation-Defined Behavior
  179. 31 CWE-762: Mismatched Memory Management Routines
  180. 32 CWE-704: Incorrect Type Conversion or Cast
  181. 33 CWE-843: Access of Resource Using Incompatible Type ('Type Confusion')
  182. 34 CWE-15: External Control of System or Configuration Setting
  183. 35 CWE-908: Use of Uninitialized Resource
  184. 36 CWE-911: Improper Update of Reference Count
  185. 37 CWE-772: Missing Release of Resource after Effective Lifetime
  186. 38 CWE-833: Improper Locking
  187. 39 CWE-413: Improper Resource Locking
  188. 40 CWE-335: Incorrect Usage of Seeds in Pseudo-Random Number Generator (PRNG)
  189. 41 CWE-468: Incorrect Pointer Scaling
  190. 42 CWE-825: Expired Pointer Dereference
  191. 43 CWE-466: Return of Pointer Value Outside of Expected Range
  192. 44 CWE-390: Detection of Error Condition Without Action
  193. 45 CWE-1069: Empty Exception Block
  194. 46 CWE-477: Use of Obsolete Function
  195. 47 CWE-676: Use of Potentially Dangerous Function
  196. 48 CWE-749: Exposed Dangerous Method or Function
  197. 49 CWE-547: Use of Hard-coded, Security-relevant Constants
  198. 50 CWE-628: Function Call with Incorrectly Specified Arguments
  199. 51 CWE-694: Use of Multiple Resources with Duplicate Identifier
  200. 52 CWE-1041: Use of Redundant Code
  201. 53 CWE-1045: Parent Class with a Virtual Destructor and a Child Class without a Virtual Destructor
  202. 54 CWE-1046: Creation of Immutable Text Using String Concatenation
  203. 55 CWE-1116: Inaccurate Comments
  204. 56 CWE-1077: Floating Point Comparison with Incorrect Operator
  205. 57 CWE-681: Incorrect Conversion between Numeric Types
  206. 58 CWE-1071: Empty Code Block
  207. 59 CWE-1126: Declaration of Variable with Unnecessarily Wide Scope
  208. 60 CWE-1113: Inappropriate Comment Style
  209. 61 CWE-1109: Use of Same Variable for Multiple Purposes
  210. 62 CWE-1108: Excessive Reliance on Global Variables
  211. 63 CWE-1102: Reliance on Machine-Dependent Data Representation
  212. 64 CWE-1098: Data Element containing Pointer Item without Proper Copy Control Element
  213. 65 CWE-1078: Inappropriate Source Code Style or Formatting
  214. 66 CWE-590: Free of Memory not on the Heap
  215. 67 CWE-664: Improper Control of a Resource Through its Lifetime
  216. 68 CWE-788: Access of Memory Location After End of Buffer
  217. 69 CWE-786: Access of Memory Location Before Start of Buffer
  218. 70 CWE-687: Function Call With Incorrectly Specified Argument Value
  219. 71 CWE-688: Function Call With Incorrect Variable or Reference as Argument
  220. 72 CWE-686: Function Call With Incorrect Argument Type
  221. 73 CWE-665: Improper Initialization
  222. 74 CWE-391: Unchecked Error Condition
  223. 75 CWE-703: Improper Check or Handling of Exceptional Conditions
  224. 76 CWE-119: Improper Restriction of Operations within the Bounds of a Memory Buffer
  225. 77 CWE-685: Function Call With Incorrect Number of Arguments
  226. 78 CWE-672: Operation on a Resource after Expiration or Release
  227. 79 CWE-771: Missing Reference to Active Allocated Resource
  228. 80 CWE-775: Missing Release of File Descriptor or Handle after Effective Lifetime
  229. 81 CWE-190: Integer Overflow or Wraparound
  230. 82 CWE-595: Comparison of Object References Instead of Object Contents
  231. 83 CWE-467: Use of sizeof() on a Pointer Type
  232. 84 CWE-682: Incorrect Calculation
  233. 85 CWE-587: Assignment of a Fixed Address to a Pointer
  234. 86 CWE-131: Incorrect Calculation of Buffer Size
  235. 87 CWE-362: Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition')
  236. 88 CWE-195: Signed to Unsigned Conversion Error
  237. 89 CWE-128: Wrap-around Error
  238. 90 CWE-597: Use of Wrong Operator in String Comparison
  239. 91 CWE-834: Excessive Iteration
  240. 92 CWE-768: Incorrect Short Circuit Evaluation
  241. 93 CWE-392: Missing Report of Error Condition
  242. 94 CWE-415: Double Free
  243. This is the top of bugs in 2021 according to mitre
  244. The list below provides insight to the community at large into the most critical and current software security weaknesses.
  245. Rank ID Name Score
  246. [1] CWE-787 Out-of-bounds Write 65.93
  247. [2] CWE-79 Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') 46.84
  248. [3] CWE-125 Out-of-bounds Read 24.9
  249. [4] CWE-20 Improper Input Validation 20.47
  250. [5] CWE-78 Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') 19.55
  251. [6] CWE-89 Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') 19.54
  252. [7] CWE-416 Use After Free 16.83
  253. [8] CWE-22 Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') 14.69
  254. [9] CWE-352 Cross-Site Request Forgery (CSRF) 14.46
  255. [10] CWE-434 Unrestricted Upload of File with Dangerous Type 8.45
  256. [11] CWE-306 Missing Authentication for Critical Function 7.93
  257. [12] CWE-190 Integer Overflow or Wraparound 7.12
  258. [13] CWE-502 Deserialization of Untrusted Data 6.71
  259. [14] CWE-287 Improper Authentication 6.58
  260. [15] CWE-476 NULL Pointer Dereference 6.54
  261. [16] CWE-798 Use of Hard-coded Credentials 6.27
  262. [17] CWE-119 Improper Restriction of Operations within the Bounds of a Memory Buffer 5.84
  263. [18] CWE-862 Missing Authorization 5.47
  264. [19] CWE-276 Incorrect Default Permissions 5.09
  265. [20] CWE-200 Exposure of Sensitive Information to an Unauthorized Actor 4.74
  266. [21] CWE-522 Insufficiently Protected Credentials 4.21
  267. [22] CWE-732 Incorrect Permission Assignment for Critical Resource 4.2
  268. [23] CWE-611 Improper Restriction of XML External Entity Reference 4.02
  269. [24] CWE-918 Server-Side Request Forgery (SSRF) 3.78
  270. [25] CWE-77 Improper Neutralization of Special Elements used in a Command ('Command Injection') 3.58
  271. This are misra error messages
  272. /* Kapitel 1 */
  273. 1,1,"All code shall conform to ISO 9899:1990 \"Programming languages - C \ E 2 \", amended and "
  274. "corrected by ISO/IEC 9899/COR1:1995, ISO/IEC 9899/AMD1:1995, and ISO/IEC 9899/COR2:1996.",MISRA|MISRA_2004,
  275. 1,2,"No reliance shall be placed on undefined or unspecified behaviour.",MISRA|MISRA_2004,
  276. 1,3,"Multiple compilers and/or languages shall only be used if there is a common defined "
  277. "interface standard for object code to which the languages/compilers/assembler conforms",MISRA|MISRA_2004,
  278. 1,4,"The compiler/linker shall be checked to ensure that 31 character significance and "
  279. "case sensitivity are supported for external identifiers",MISRA|MISRA_2004,
  280. 1,5,"Floating point implementations should comply with a defined floating-point standard",MISRA|MISRA_2004,
  281. /* Kapitel 2 */
  282. 2,1,"Assembly language shall be encapsulated and isolated",MISRA|MISRA_2004,
  283. 2,2,"Source code shall only use /* ... */ style comments",MISRA|MISRA_2004,
  284. 2,3,"The character sequence /* shall not be used within a comment",MISRA|MISRA_2004,
  285. 2,4,"Sections of code should not be \"commented out\"",MISRA|MISRA_2004,
  286. /* Kapitel 3 */
  287. 3,1,"All usage of implementation-defined behaviour shall be documented ",MISRA|MISRA_2004,
  288. 3,2,"The character set and corresponding encoding shall be documented",MISRA|MISRA_2004,
  289. 3,3,"The implementation of integer division in the chosen compiler should "
  290. "be determined, documented and taken into account",MISRA|MISRA_2004,
  291. 3,4,"All use of the #pragma directive shall be documented and explained",MISRA|MISRA_2004,
  292. 3,5,"If it is being relied upon, the implementation-defined behaviour and "
  293. "packing of bitfields shall be documented",MISRA|MISRA_2004,
  294. 3,6,"All libraries used in production code shall be written to comply with "
  295. "the provisions of this document, and shall have been subject to appropriate validation",MISRA|MISRA_2004,
  296. /* Kapitel 4 */
  297. 4,1,"Only those escape sequences that are defined in the ISO C standard shall be used",MISRA|MISRA_2004|MISRA_PREPROC,
  298. 4,2,"Trigraphs shall not be used",MISRA|MISRA_2004,
  299. /* Kapitel 5*/
  300. 5,1,"Identifiers (internal and external) shall not rely on the significance "
  301. "of more than 31 characters",MISRA|MISRA_2004,
  302. 5,2,"Identifiers in an inner scope shall not use the same name as an identifier "
  303. "in an outer scope, and therefor hide that identifier",MISRA|MISRA_2004,
  304. 5,3,"A typedef name shall be a unique identifier",MISRA|MISRA_2004,
  305. 5,4,"A tag name shall be a unique identifier",MISRA|MISRA_2004,
  306. 5,5,"No object or function identifier with static storage duration should be reused",MISRA|MISRA_2004,
  307. 5,6,"No identifier in one name space should have the same spelling as an identifier "
  308. "in another name space, with the exception of structure and union member names",MISRA|MISRA_2004,
  309. 5,7,"No identifier name should be reused",MISRA|MISRA_2004,
  310. /* Kapitel 6 */
  311. 6,1,"The plain char type shall be used only for the storage and use of character values",MISRA|MISRA_2004,
  312. 6,2,"signed and unsigned char type shall be used only for the storage and use of numeric values",MISRA|MISRA_2004,
  313. 6,3,"typedefs that indicate size and signedness should be used in place of the basic types",MISRA|MISRA_2004,
  314. 6,4,"Bit fields shall only be defined to be of type unsigned int or signed int",MISRA|MISRA_2004,
  315. 6,5,"Bit fields of type signed int shall be at least 2 bit long",MISRA|MISRA_2004,
  316. /* Kapitel 7 */
  317. 7,1,"Octal constants (other than zero) and octal escape sequences shall not be used",MISRA|MISRA_2004,
  318. /* Kapitel 8 */
  319. 8,1,"Functions shall have prototype declaration and the prototype shall "
  320. "be visible at both the function definition and call",MISRA|MISRA_2004,
  321. 8,2,"Whenever an object or function is declared or defined, its type shall "
  322. "be explicitly stated",MISRA|MISRA_2004,
  323. 8,3,"For each function parameter the type given in the declaration and "
  324. "definition shall be identical, and the return type shall also be identical",MISRA|MISRA_2004,
  325. 8,4,"If objects or functions are declared more than once their type shall be compatible",MISRA|MISRA_2004,
  326. 8,5,"There shall be no definition of objects or functions in a header file",MISRA|MISRA_2004,
  327. 8,6,"Functions shall be declared at file scope",MISRA|MISRA_2004,
  328. 8,7,"Objects shall be defined at block scope if they are only accessed from "
  329. "within a single function",MISRA|MISRA_2004,
  330. 8,8,"An external object or function shall be declared in one and only one file",MISRA|MISRA_2004,
  331. 8,9,"An identifier with external linkage shall have excactly one external definition",MISRA|MISRA_2004,
  332. 8,10,"All declarations and definitions of objects and functions at file scope shall "
  333. "have internal linkage unless external linkage is required",MISRA|MISRA_2004,
  334. 8,11,"The static storage class specifier shall be used in definitions and declarations "
  335. "of objects and functions that have internal linkage",MISRA|MISRA_2004,
  336. 8,12,"When an array is declared with external linkage, its size shall be stated "
  337. "or defined implicitly be initialisation",MISRA|MISRA_2004,
  338. /* Kapitel 9 */
  339. 9,1,"All automatic variables shall have been assigned a value before being used",MISRA|MISRA_2004,
  340. 9,2,"Braces shall be used to indicate and match the structure in the non-zero "
  341. "initialisation of arrays and structures",MISRA|MISRA_2004,
  342. 9,3,"In an enumerator list, the \"=\" construct shall not be used to explicitly "
  343. "initialise members other than the first, unless all items are explicitly initialised",MISRA|MISRA_2004,
  344. /* Kapitel 10 */
  345. 10,1,"The value of an expression of integer type shall not be implicitly converted to a different underlying type if: \n"
  346. " a) it is not a conversion to a wider integer type of the same signedness, or\n"
  347. " b) the expression is complex, or\n"
  348. " c) the expression is not constant and is a function argument, or\n"
  349. " d) the expression is not constant and is a return expression",MISRA|MISRA_2004,
  350. 10,2,"The value of an expression of floating type shall not be implicitly converted to a different type if:\n"
  351. " a) it is not a conversion to a wider floating type, or\n"
  352. " b) the expression is complex, or\n"
  353. " c) the expression is a function argument, or\n"
  354. " d) the expression is a return expression\n",MISRA|MISRA_2004,
  355. 10,3,"The value of a complex expression of integer type may only be cast "
  356. "to a atype that is narrower and of the same signedness as the "
  357. "underlying type of the expression",MISRA|MISRA_2004,
  358. 10,4,"The value of a complex expression of floating type may only be cast "
  359. "to a narrower floating type",MISRA|MISRA_2004,
  360. 10,5,"If the bitwise operators ~ and << are applied to an operand of "
  361. "underlying type unsigned char or unsigned short, the result "
  362. "shall be immediately cast to the underlying type of the operand",MISRA|MISRA_2004,
  363. 10,6,"A \"U\" suffix shall be applied to all constants of unsigned type",MISRA|MISRA_2004,
  364. /* Kapitel 11 */
  365. 11,1,"Conversions shall not be performed between a pointer to a function and any type "
  366. "other than an integral type",MISRA|MISRA_2004,
  367. 11,2,"Conversions shall not be performed between a pointer to object and any type "
  368. "other than an integral type, another pointer to object type or a pointer to void",MISRA|MISRA_2004,
  369. 11,3,"A cast should not be performed between a pointer type and an integral type",MISRA|MISRA_2004,
  370. 11,4,"A cast should not be performed between a pointer to object type and a "
  371. "different pointer to object type.",MISRA|MISRA_2004,
  372. 11,5,"A cast shall not be performed that removes any const or volatile qualification "
  373. "from the type addresses by a pointer",MISRA|MISRA_2004,
  374. /* Kapitel 12 */
  375. 12,1,"Limited dependence should be placed on C's operator precedence rules in expressions",MISRA|MISRA_2004,
  376. 12,2,"The value of an expression shall be the same under any order of "
  377. "evaluation that the standard permits",MISRA|MISRA_2004,
  378. 12,3,"The sizeof operator shall not be used on expressions that contain side effects",MISRA|MISRA_2004,
  379. 12,4,"The right-hand operand of a logical && or || operator shall not "
  380. "contain side effects",MISRA|MISRA_2004,
  381. 12,5,"The operands of a logical && or || shall be primary-expressions",MISRA|MISRA_2004,
  382. 12,6,"The operands of logical operators (&&, || and !) should be effectively Boolean, "
  383. "Expressions that are effectively Booleand should not be used as operands to "
  384. "eperators other than(&&, || and !)",MISRA|MISRA_2004,
  385. 12,7,"Bitweise operators shall not be applied to operands whose underlying type is signed",MISRA|MISRA_2004,
  386. 12,8,"The right-hand operand of a shift operator shall lie between zero and one less "
  387. "than the width in bits of ther underlying type of the left-hand operand.",MISRA|MISRA_2004,
  388. 12,9,"The unary minus operator shall not be applied to an expression whose underlying type is unsigned",MISRA|MISRA_2004,
  389. 12,10,"The comma operator shall not be used",MISRA|MISRA_2004,
  390. 12,11,"Evaluation of constant unsigned integer expressions should not lead to wrap-around",MISRA|MISRA_2004,
  391. 12,12,"The underlying bit representation of floating-point values shall not be used",MISRA|MISRA_2004,
  392. 12,13,"The increment (++) and decrement (--) operators should not be mixed with other "
  393. "operators in an expression",MISRA|MISRA_2004,
  394. /* Kapitel 13 */
  395. 13,1,"Assignment opetaors shall not be used in expressions that yield a Boolean value",MISRA|MISRA_2004,
  396. 13,2,"Tests of a value against zero should be made explicit, unless the operand is effectively Boolean",MISRA|MISRA_2004,
  397. 13,3,"Floating-point expressions shall not be tested for equality or inequality",MISRA|MISRA_2004,
  398. 13,4,"The controlling expression of a for statement shall not contain any objects of floating type.",MISRA|MISRA_2004,
  399. 13,5,"The three expressions of a for statement shall be concerned only with loop control",MISRA|MISRA_2004,
  400. 13,6,"Numeric variables being used within a for loop for iteration counting shall not be modified in the body of the loop",MISRA|MISRA_2004,
  401. 13,7,"Boolean operations whose results are invariant shall not be permitted",MISRA|MISRA_2004,
  402. /* Kapitel 14 */
  403. 14,1,"There shall be no unreachable code",MISRA|MISRA_2004,
  404. 14,2,"All non-null statements shall either:\n"
  405. " a) have at least one side-effect however executed, or\n"
  406. " b) cause control flow to change",MISRA|MISRA_2004,
  407. 14,3,"Before preprocessing, a null statement shall only occur on a line by itself; it may be "
  408. "followed by a comment provided that the first character following the null statement "
  409. "is a white-space character.",MISRA|MISRA_2004,
  410. 14,4,"The goto statement shall not be used",MISRA|MISRA_2004,
  411. 14,5,"The continue statement shall not be used",MISRA|MISRA_2004,
  412. 14,6,"For any interation statement there shall be at most one braek statement used for loop termination",MISRA|MISRA_2004,
  413. 14,7,"A function shall have a single point of exit at the end of the function",MISRA|MISRA_2004,
  414. 14,8,"The statement forming the body of a switch, while, do ... while or for statement "
  415. "shall be a compound statement",MISRA|MISRA_2004,
  416. 14,9,"An if (expression) construct shall be followed by a compound statement. The else "
  417. "keyword shall be followed by either a compound statement, or another if statement",MISRA|MISRA_2004,
  418. 14,10,"All if ... else if constructs shall be terminated with an else clause",MISRA|MISRA_2004,
  419. /* Kapitel 15 */
  420. 15,1,"A switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statement",MISRA|MISRA_2004,
  421. 15,2,"An unconditional break statement shall terminate every non-empty switch clause",MISRA|MISRA_2004,
  422. 15,3,"The final clause of a switch statement shall be the default clause",MISRA|MISRA_2004,
  423. 15,4,"A Switch expression shall not represent a value that is effectively Boolean",MISRA|MISRA_2004,
  424. 15,5,"Every switch statement shall have at least one case clause",MISRA|MISRA_2004,
  425. /* Kapitel 16 */
  426. 16,1,"Functions shall not be defined with a variable number of arguments",MISRA|MISRA_2004,
  427. 16,2,"Functions shall not call themselves, either directly or indirectly",MISRA|MISRA_2004,
  428. 16,3,"Identifiers shall be given for all of the parameters in a function prototype declaration",MISRA|MISRA_2004,
  429. 16,4,"The identifiers used in the declaration and definition of a function shall be identical",MISRA|MISRA_2004,
  430. 16,5,"Functions with no parameters shall be declared with parameter type void",MISRA|MISRA_2004,
  431. 16,6,"The number of arguments passed to a function shall match the number of parameters",MISRA|MISRA_2004,
  432. 16,7,"A pointer parameter in a function prototype should be declared as pointer to const "
  433. "if the pointer is not used to modify the addressed object",MISRA|MISRA_2004,
  434. 16,8,"All exit paths from a function with non-void return type shall have an explicit "
  435. "return statement with an expression",MISRA|MISRA_2004,
  436. 16,9,"A function identifier shall only be used with either a preceding &, or with a "
  437. "parenthesised parameter list, which may be empty",MISRA|MISRA_2004,
  438. 16,10,"If a function returns error information, then that error information shall be tested",MISRA|MISRA_2004,
  439. /* Kapitel 17 */
  440. 17,1,"Pointer arithmetic shall only be applied to pointers that address an array or array element",MISRA|MISRA_2004,
  441. 17,2,"Pointer subtraction shall only be apllied to pointers that address elements of the same array",MISRA|MISRA_2004,
  442. 17,3,">, >=, <, <= shall not be applied to pointer types except where they point to the same array",MISRA|MISRA_2004,
  443. 17,4,"Array indexing shall be the only allowed form of pointer arithmetic",MISRA|MISRA_2004,
  444. 17,5,"The declaration of objects should contain no more than 2 levels of pointer indirection",MISRA|MISRA_2004,
  445. 17,6,"The address of an object with automatic storage shall not be assigned to an other "
  446. "object that may persist after the first object has ceased to exist",MISRA|MISRA_2004,
  447. /* Kapitel 18 */
  448. 18,1,"All structure and union types shall be complete at the end of a translation unit",MISRA|MISRA_2004,
  449. 18,2,"An object shall not be assigned to an overlapping object",MISRA|MISRA_2004,
  450. 18,3,"An area of memory shall not be reused for unrelated purposes",MISRA|MISRA_2004,
  451. 18,4,"Unions shall not be used",MISRA|MISRA_2004,
  452. /* Kapitel 19 */
  453. 19,1,"#include statements in a file should only be preceded by other preprocessor directives or comments",MISRA|MISRA_2004,
  454. 19,2,"Non-standard characters should not occur in header file names in #include directives",MISRA|MISRA_2004,
  455. 19,3,"The #include directive shall be followed by either a <filename> or \"filename\" sequence",MISRA|MISRA_2004,
  456. 19,4,"C macros shall only expand to a braced initialiser, a constant, a parenthesised "
  457. "expression, a type qualifier, a storage class specifier, or a do-while-zero construct",MISRA|MISRA_2004,
  458. 19,5,"Macros shall not be #defined'd or #undef'd within a block",MISRA|MISRA_2004,
  459. 19,6,"#undef shall not be used",MISRA|MISRA_2004,
  460. 19,7,"A function should be used in preference to a function-like macro",MISRA|MISRA_2004,
  461. 19,8,"A function-like macro shall not be invoked without all of its arguments",MISRA|MISRA_2004,
  462. 19,9,"Arguments to a function-like macro shall not contain tokens that look like preprocessing directives",MISRA|MISRA_2004,
  463. 19,10,"In the definition of a function-like macro each instance of a parameter shall be enclosed "
  464. "in parentheses unless it is used as the operand of # or ##",MISRA|MISRA_2004,
  465. 19,11,"All macro identifiers in preprocessor directives shall be defined before use, except "
  466. "in #ifdef and #ifndef preprocessor directives and the defined() operator",MISRA|MISRA_2004,
  467. 19,12,"There shall be at most one occurrence of the # or ## preprocessor operators in a "
  468. "single macro definition",MISRA|MISRA_2004,
  469. 19,13,"The # and ## preprocessor operators should not be used",MISRA|MISRA_2004,
  470. 19,14,"The defined preprocessor operator shall only be used in one of the two standard forms",MISRA|MISRA_2004,
  471. 19,15,"Precautions shall be taken in order to prevent the contents of a header file being included twice",MISRA|MISRA_2004,
  472. 19,16,"Preprocessing directives shall be syntactically meaningful even when excluded by the preprocessor",MISRA|MISRA_2004,
  473. 19,17,"All #else, #elif and #endif preprocessor directives shall reside in the same file as "
  474. "the #if or #ifdef directive to which they are related",MISRA|MISRA_2004,
  475. /* Kapitel 20 */
  476. 20,1,"Reserved identifiers, macros and functions in the standard library, shall not "
  477. "be defined, redefined or undefined",MISRA|MISRA_2004,
  478. 20,2,"The names of standard library macros, objects and functions shall not be reused",MISRA|MISRA_2004,
  479. 20,3,"The validity of values passed to library functions shall be checked",MISRA|MISRA_2004,
  480. 20,4,"Dynamic heap memory allocation shall not be used",MISRA|MISRA_2004,
  481. 20,5,"The error indicator errno shall not be used",MISRA|MISRA_2004,
  482. 20,6,"The macro offsetof, in library <stddef.h>, shall not be used",MISRA|MISRA_2004,
  483. 20,7,"The setjmp macro and the longjmp function shall not be used",MISRA|MISRA_2004,
  484. 20,8,"The signal handling facilities of <signal.h> shall not be used",MISRA|MISRA_2004,
  485. 20,9,"The input/output library <stdio.h> shall not be used in production code",MISRA|MISRA_2004,
  486. 20,10,"The library functions atof, atoi and atol from library <stdlib.h> shall not be used",MISRA|MISRA_2004,
  487. 20,11,"The library functions abort, exit, getenv and system from library <stdlib.h> shall not be used.",MISRA|MISRA_2004,
  488. 20,12,"The time handling functions of library <time.h> shall not be used",MISRA|MISRA_2004,
  489. /* Kapitel 21 */
  490. 21,1,"Minimisation of run-time failures shall be ensured by the use of at least one of:\n"
  491. " a) static analysis tools/techniques\n"
  492. " b) dynamic analysis tools/techniques\n"
  493. " c) explicit coding of checks to handle run-time faults",MISRA|MISRA_2004,
  494. The ckermit software has much experience to create poratble c and have recommendations at
  495. https://www.kermitproject.org/ckcplm.html
  496. Try to keep variable and function names unique within 6 characters, especially if they are used across modules, since 6 is the maximum for some old linkers (actually, this goes back to TOPS-10 and -20 and other old DEC OS's where C-Kermit never ran anyway; a more realistic maximum is probably somewhere between 8 and 16). We know for certain that VAX C has a 31-character max because it complains -- others might not complain, but just silently truncate, thus folding two or more routines/variables into one.
  497. Keep preprocessor symbols unique within 8 characters; that's the max for some preprocessors (sorry, I can't give a specific example, but in 1988 or thereabouts, I had to change character-set symbols like TC_LATIN1 and TC_LATIN2 to TC_1LATIN and TC_2LATIN because the digits were being truncated and ignored on a platform where I actually had to build C-Kermit 5A; unfortunately I didn't note which platform -- maybe some early Ultrix version?)
  498. Don't create preprocessor symbols, or variable or function names, that start with underscore (_). These are usually reserved for internal use by the compiler and header files.
  499. Don't put #include directives inside functions or { blocks }.
  500. Don't use the #if or #elif preprocessor constructions, only use #ifdef, #ifndef, #define, #undef, and #endif. C-Kermit must be buildable on old as well as new platforms, and computers are still running whose C preprocessors do not support these constructions. Not even within #ifdef..#endif, because cpp reads all directives that start with # (e.g. to find the matching #endif for the most recent #ifdef) and when it encounters an unknown directive, it stops with a fatal error.
  501. Put tokens after #endif in comment brackets, e.g. #endif /* FOO */.
  502. Don't indent preprocessor statements - # must always be first char on line.
  503. Don't put whitespace after # in preprocessor statements.
  504. Don't use #pragma, even within #ifdefs -- it makes some preprocessors give up.
  505. Same goes for #module, #if, etc - #ifdefs do NOT protect them.
  506. Don't use logical operators in preprocessor constructions.
  507. Avoid #ifdefs inside argument list to function calls (I can't remember why this one is here, but probably needn't be; we do this all the time).
  508. Always cast strlen() in expressions to int:
  509. if ((int)strlen(foo) < x)...
  510. Avoid typedefs; they might be portable but they are very confusing and there's no way to test for their presence or absence at compile time. Use preprocessor symbols instead if possible; at least you can test their definitions.
  511. Unsigned long is not portable; use a preprocessor symbol (Kermit uses ULONG for this).
  512. Long long is not portable. If you really need it, be creative.
  513. Similarly 1234LL is not portable, nor almost any other constant modifier other than L.
  514. Unsigned char is not portable, use CHAR (a preprocessor symbol defined in the Kermit header files) and always take precautions against character signage (more about this below).
  515. Don't use initializers with automatic arrays or structs: it's not portable.
  516. Don't use big automatic arrays or structs in functions that might be called recursively; some platforms have fixed-size stacks (e.g. Windows 9x: 256K) and recursive functions crash with stack overflow. Even when there is not a compiler limitation, this causes memory to be consumed without bound, and can end up filling swap space.
  517. Don't assume that struct assignment performs a copy, or that it even exists.
  518. Don't use sizeof to get the size of an array; someone might come along later and and change it from static to malloc'd. Always use a symbol to refer to the array's size.
  519. Don't put prototypes for static functions into header files that are used by modules that don't contain that function; the link step can fail with unresolved references (e.g. on AOS/VS).
  520. Avoid the construction *++p (the order of evaluation varies; it shouldn't but at least one compiler had a bug that made me include this item).
  521. Don't use triple assignments, like a = b = c = 0; (or quadruple, etc). Some compilers generate bad code for these, or crash, etc (some version of DEC C as I recall).
  522. Some compilers don't allow structure members to have the same names as other identifiers. Try to give structure members unique names.
  523. Don't assume anything about order of evaluation in boolean expressions, or that they will stop early if a required condition is not true, e.g.:
  524. if (i > 0 && p[i-1] == blah)
  525. can still dump core if i == 0 (hopefully this is not true of any modern compiler, but I would not have said this if it did not actually happen somewhere).
  526. Don't have a switch() statement with no cases (e.g. because of #ifdefs); this is a fatal error in some compilers.
  527. Don't put lots of code in a switch case; move it out to a separate function; some compilers run out of memory when presented with a huge switch() statement -- it's not the number of cases that matters; it's the overall amount of code.
  528. Some compilers might also limit the number of switch() cases, e.g. to 254.
  529. Don't put anything between "switch() {" and "case:" -- switch blocks are not like other blocks.
  530. Don't jump into or out of switches.
  531. Don't make character-string constants longer than about 250 bytes. Longer strings should be broken up into arrays of strings.
  532. Don't write into character-string constants (obviously). Even when you know you are not writing past the end; the compiler or linker might have put them into read-only and/or shared memory, and/or coalesced multiple equal constants so if you change one you change them all.
  533. Don't depend on '\r' being carriage return.
  534. Don't depend on '\n' being linefeed or for that matter any SINGLE character.
  535. Don't depend on '\r' and '\n' being different (e.g. as separate switch() cases).
  536. In other words, don't use \n or \r to stand for specific characters; use \012 and \015 instead.
  537. Don't code for "buzzword 1.0 compliance", unless "buzzword" is K&R and "1.0" is the first edition.
  538. Don't use or depend on anything_t (size_t, pid_t, etc), except time_t, without #ifdef protection (time_t is the only one I've found that is accepted everywhere). This is a tough one because the same function might require (say) a size_t arg on one platform, whereas size_t is unheard of on another; or worse, it might require a totally different data type, like int or long or some other typedef'd thing. It has often proved necessary to define a symbol to stand for the type of a particular argument to a particular library or system function to get around this problem.
  539. Don't use or depend on internationalization ("i18n") features, wchar_t, locales, etc, in portable code; they are not portable. Anyway, locales are not the right model for Kermit's multi-character-set support. Kermit does all character-set conversion itself and does not use any external libraries or functions.
  540. In particular, don't use any library functions that deal with wide characters or Unicode in any form. These are not only nonportable, but a constantly shifting target (e.g. the ones in glibc).
  541. Don't make any assumption about signal handler type. It can be void, int, long, or anything else. Always declare signal handlers as SIGTYP (see definition in ckcdeb.h and augment it if necessary) and always use SIGRETURN at exit points from signal handlers.
  542. Signals should always be re-armed to be used again (this barely scratches the surface -- the differences between BSD/V7 and System V and POSIX signal handling are numerous, and some platforms do not even support signals, alarms, or longjmps correctly or at all -- avoid all of this if you can).
  543. On the other hand, don't assume that signals are disarmed after being raised. In some platforms you have to re-arm them, in others they stay armed.
  544. Don't call malloc() and friends from a signal handler; don't do anything but setting integer global variables in a signal handler.
  545. malloc() does not initialize allocated memory -- it never said it did. Don't expect it to be all 0's.
  546. Did You Know: malloc() can succeed and the program can still dump core later when it attempts to use the malloc'd memory? (This happens when allocation is deferred until use and swap space is full.)
  547. memset(), memmove(), and memcpy() are not portable, don't use them without protecting them in ifdefs (we have USE_MEMCPY for this). bzero()/bcopy() too, except we're guaranteed to have bzero()/bcopy() when using the sockets library (not really). See examples in the source.
  548. Don't assume that strncpy() stops on the first null byte -- most versions always copy the number of bytes given in arg 3, padding out with 0's and overwriting whatever was there before. Use C-Kermit ckstrncpy() if you want predictable non-padding behavior, guaranteed NUL-termination, and a useful return code.
  549. DID YOU KNOW.. that some versions of inet_blah() routines return IP addresses in network byte order, while others return them local machine byte order? So passing them to ntohs() or whatever is not always the right thing to do.
  550. Don't use ANSI-format function declarations without #ifdef CK_ANSIC, and always provide an #else for the non-ANSI case.
  551. Use the Kermit _PROTOTYP() macro for declaring function prototypes; it works in both the ANSI and non-ANSI cases.
  552. Don't depend on any other ANSI preprocessor features like "pasting" -- they are often missing or nonoperational.
  553. Don't assume any C++ syntax or semantics.
  554. Don't use // as a comment introducer. C is not C++.
  555. Don't declare a string as "char foo[]" in one module and "extern char * foo" in another, or vice-versa: this causes core dumps.
  556. With compiler makers falling all over themselves trying to outdo each other in ANSI strictness, it has become increasingly necessary to cast EVERYTHING. Especially char vs unsigned char. We need to use unsigned chars if we want to deal with 8-bit character sets, but most character- and string-oriented APIs want (signed) char arguments, so explicit casts are necessary. It would be nice if every compiler had a -funsigned-char option (as gcc does), but they don't.
  557. a[x], where x is an unsigned char, can produce a wild memory reference if x, when promoted to an int, becomes negative. Cast it to (unsigned), even though it ALREADY IS unsigned.
  558. Be careful how you declare functions that have char or long arguments; for ANSI compilers you MUST use ANSI declarations to avoid promotion problems, but you can't use ANSI declarations with non-ANSI compilers. Thus declarations of such functions must be hideously entwined in #ifdefs. Example:
  559. int /* Put character in server command buffer */
  560. #ifdef CK_ANSIC
  561. putsrv(char c)
  562. #else
  563. putsrv(c) char c;
  564. #endif /* CK_ANSIC */
  565. /* putsrv */ {
  566. *srvptr++ = c;
  567. *srvptr = '\0'; /* Make sure buffer is null-terminated */
  568. return(0);
  569. }
  570. Be careful how you return characters from functions that return int values -- "getc-like functions" -- in the ANSI world. Unless you explicitly cast the return value to (unsigned), it is likely to be "promoted" to an int and have its sign extended.
  571. At least one compiler (the one on DEC OSF/1 1.3) treats "/*" and "*/" within string constants as comment begin and end. No amount of #ifdefs will get around this one. You simply can't put these sequences in a string constant, e.g. "/usr/local/doc/*.*".
  572. Avoid putting multiple macro references on a single line, e.g.:
  573. putchar(BS); putchar(SP); putchar(BS)
  574. This overflows the CPP output buffer of more than a few C preprocessors (this happened, for example, with SunOS 4.1 cc, which evidently has a 1K macro expansion buffer).
  575. ---
  576. p5js.org is drawing library and has a gui creation tool and more usable libraries