HP Code Advisor Diagnostics Reference Guide HP Part Number: 5900-1865 Published: September 2012 Edition: 5
© Copyright 2011 Hewlett-Packard Development Company, L.P. Confidential computer software. Valid license from HP required for possession, use or copying. Consistent with FAR 12.211 and 12.212, Commercial Computer Software, Computer Software Documentation, and Technical Data for Commercial Items are licensed to the U.S. Government under vendor's standard commercial license. The information contained herein is subject to change without notice.
Contents About This Document.....................................................................................7 Intended Audience....................................................................................................................7 HP Encourages Your Comments..................................................................................................7 1 Diagnostics Categorization..........................................................................8 Default Diagnostics...........
2224 the format string requires additional arguments..................................................................34 2225 the format string ends before this argument........................................................................34 2226 invalid format string conversion........................................................................................34 2228 trailing comma is nonstandard.........................................................................................
3055 types cannot be declared in anonymous unions.................................................................49 3056 returning pointer to local variable....................................................................................49 3105 #warning directive: %s....................................................................................................49 3138 format argument does not have string type.........................................................................
4295 abstract function type declared with empty parentheses, consider replacing with parameter list or void. ................................................................................................................................64 4298 64 bit migration: addition result could be truncated before cast to bigger sized type...............64 4299 64 bit migration: multiply result could be truncated before cast to bigger sized type................
About This Document This document provides a brief description for a partial list of diagnostics emitted by Cadvise. There are four sections for each description as mentioned below: • The Cause section Discusses the possible reasons for the diagnostic to be emitted. • The Example section Provides relevant sample code segments that result in the specific diagnostic.
1 Diagnostics Categorization This chapter addresses the diagnostics categorization for HP Code Advisor. NOTE: • Some of the diagnostic numbers given below do not have a corresponding diagnostic description. Incase you need a diagnostic description for a diagnostic number, please send an email to: cadvise-help@lists.hp.com • The diagnostics with number greater than 20000 are more effective when cross-file analysis is enabled. For more information on cross-file analysis, see HP Code Advisor User's Guide.
Table 1 Default diagnostics (continued) Diagnostic number Diagnostic message 2149 a global-scope declaration may not have this storage class 2155 old-fashioned assignment operator 2157 expression must be an integral constant expression 2161 unrecognized #pragma 2165 too few arguments in function call 2167 argument of type %t1 is incompatible with parameter of type %t2 2174 expression has no effect 2175 subscript out of range 2178 \"&\" applied to an array has no effect 2181 argument is
Table 1 Default diagnostics (continued) 10 Diagnostic number Diagnostic message 2460 declaration of %sq hides function parameter 2472 member function typedef (allowed for cfront compatibility) 2490 %n cannot be instantiated -- it has been explicitly specialized 2495 global %n1 used instead of %n2 (cfront compatibility) 2497 declaration of %sq hides template parameter 2514 pointless comparison of unsigned integer with a negative constant 2524 non-const function called for const object (anach
Table 1 Default diagnostics (continued) Diagnostic number Diagnostic message 2836 returning reference to local variable 2855 return type is not identical to return type %t of overridden virtual function %n 2867 declaration of \"size_t\" does not match the expected type %t 2902 type qualifier ignored 2925 type qualifiers on function types are ignored 2959 declared size for bit field is larger than the size of the bit field type; ; truncated to %s bits 2991 extra braces are nonstandard 2997 %
Table 1 Default diagnostics (continued) 12 Diagnostic number Diagnostic message 3197 the prototype declaration of %nfd is ignored after this unprototyped redeclaration 3202 call of zero constant ignored 3210 declaration of %sq hides handler parameter 3211 nonstandard cast to array type ignored 3213 field uses tail padding of a base class 3214 GNU C++ compilers may use bit field padding 3215 %nd was declared \"deprecated\" 3217 unrecognized format function type %sq ignored 3218 base clas
Table 1 Default diagnostics (continued) Diagnostic number Diagnostic message 3346 function returns incomplete class type %t 3347 %n has already been initialized; the out-of-class initializer will be ignored 3359 variable attributes appearing after a parenthesized initializer are ignored 3360 the result of this cast cannot be used as an lvalue 3361 negation of an unsigned fixed-point value 3377 friend specifier is not allowed in a class definition; friend specifier is ignored 3386 storage spec
Table 1 Default diagnostics (continued) Diagnostic number Diagnostic message 3627 attribute \"cleanup\" requires automatic storage duration 3628 attribute \"cleanup\" does not apply to parameters 3644 definition at end of file not followed by a semicolon or a declarator 3647 extra arguments ignored 3650 result of call is not used 3651 attribute is ignored for void return type 3652 attribute requires pointer-to-function type 3653 dllimport/dllexport is ignored on redeclaration using a qualif
Table 1 Default diagnostics (continued) Diagnostic number Diagnostic message 4162 This feature, within an OpenMP directive region, is not supported by this version of C++. All surrounding OpenMP processing pragmas are being ignored.
Table 1 Default diagnostics (continued) Diagnostic number Diagnostic message 4288 Object %sq in pragma noptrs_to_globals may not have its address taken, pragma ignored 4294 the use of pragma %s is not allowed in this environment 4301 expression has no effect 4308 case label constant out of range (%s) for switch expression 4313 no prototype or definition in scope for call to memory allocation routine %sq 4321 One or more source files were inaccessible (error: %s) while emitting the source contex
Table 3 +wlint diagnostics (continued) Diagnostic number Diagnostic message 2401 destructor for base class %nod is not virtual 2550 %n was set but never used 2767 conversion from pointer to smaller integer 2108 signed bit field of length 1 2815 type qualifier on return type is meaningless 2940 missing return statement at end of non-void 3051 standard requires that %n be given a type by a subsequent declaration ("int" assumed) 3053 conversion from integer to smaller pointer 3348 declaratio
Table 3 +wlint diagnostics (continued) Diagnostic number Diagnostic message 4354 One of the operands of the %sq operation is a string literal, strcmp() is recommended for such comparison 4357 octal escape sequence "%s" is followed by decimal character '%s2' 20200 Potential null pointer dereference %s%s is detected %s 20201 Memory leak is detected 20202 Allocated memory may potentially be leaked %s 20203 Potential out of scope use of local %s %s 20204 Potential out of scope use of alloca retur
Table 4 +w64bit diagnostics (continued) Diagnostic number Diagnostic message 4229 64 bit migration: conversion from %t1 to %t2 may truncate value 4230 64 bit migration: conversion from %t1 to %t2 may cause target of pointers to have a different size. 4231 64 bit migration: conversion between types of different sizes has occurred (from %t1 to %t2 ) 4249 64 bit migration: value could be truncated before cast to bigger sized type.
Table 6 +wsecurity diagnostics (continued) Diagnostic number Diagnostic message 20119 (SECURITY) Unsafe API '%s' is used.%s 20132 (SECURITY) %%s is used in the format string for input, potential buffer overflow may occur in %s argument 20212 (SECURITY) Improper creation of temporary file using 'fopen' can lead to race condition. Use 'open' with O_CREAT|O_EXCL flag instead +wlock Diagnostics Following table lists diagnostic messages that cadvise emits when you use the +wlock command line option.
Table 8 +wperfadvice diagnostics (continued) Diagnostic number Diagnostic message 20311 performance advice: Loop iterated %s times during %s%% of total invocations. Multi-versioning the loop with the constant iteration count could enable a dditional optimizations. If this loop is one of the inner loops of a loop nest, consider multi-versioning it along with the enclosing loops. 20312 performance advice: Parallelizing this loop will likely provide better performance.
Table 9 +w/+w1 diagnostics (continued) Diagnostic number Diagnostic message 3353 %n has no corresponding member operator delete%s (to be called if an exception is thrown during initialization of an allocated object) 4049 vtable generation for classes with no key functions already %s, pragma ignored 4080 explicit request to instantiate %n ignored because of directive %p 4161 OpenMP directives are not active in this compilation because the +Oopenmp option was not specified on the command line.
Table 10 Diagnostic messages that are turned off by default Diagnostic number Diagnostic message 4246 ignoring return value of %n 4325 64 bit migration: struct %sq (recursively) contains a long or pointer field, its size will change based on the data model 4360 size of types of consecutive bitfields are different, bitfield packing behavior may be different across compiler 4361 64 bit migration: size of types of consecutive bitfields are different, bitfield packing behavior may be different across c
2 Diagnostics Details This chapter provides the detailed description for a subset of diagnostics emitted by HP Code Advisor. 2009 nested comment is not allowed Cause: Opening comment delimiter, /*, found inside delimited comment. A previous comment may be missing its closing delimiter. C comments delimited by /* */ do not nest.
Action: Use valid/compatible operand types or use a cast operator to convert one operand type to the other type. Reference: 2047 incompatible redefinition of macro %nod Cause: A #define preprocessing directive has redefined a macro whose previous definition contained an error or warning. Normally, the compiler will issue a warning if a macro is redefined to something other than the previous definition.
2064 declaration does not declare anything Cause: The declaration does not declare anything. The C standard requires that a declaration must declare at least a tag, an enumeration constant or a declarator. Example: int; Action: Correct or remove the declaration. Reference: C99 6.7.2, ANSI/ISO C++ 6.7(2) 2068 integer conversion resulted in a change of sign Cause: Conversion of integer resulted in sign change. Either an unsigned 1-bit bitfield was assigned -1, or a signed 1-bit bitfield was assigned 1.
Example: struct X { i; }; Action: Provide a declaration specifier. Reference: C99 6.7.2 2082 storage class is not first Cause: The placement of a storage-class specifier other than at the beginning of the declaration specifier in a declaration is an obsolescent feature. Example: int static i = 0; Action: Place the storage-class specifier first in the declaration. Reference: C99 6.7, 6.7.
2111 statement is unreachable Cause: Code at this location will never be executed. Often unreachable statements represent a real coding error such as a wrongly inserted return, goto, throw or call to non-returning functions etc. Example: return 0; i++; // warning 2111 here Action: Check for incorrectly placed unconditional control transfer statements. Reference: 2117 non-void %n should return a value Cause: A function that returns a value does not end with a return statement.
Action: If the loop is necessary, change the code such that the loop can be reached. Otherwise, remove the loop. Reference: 2144 a value of type %t1 cannot be used to initialize an entity of type %t2 Cause: Initializing an entity of some type with incompatible types. Example: typedef char* addr; int main() { addr data = "0x1"; int bar = data; return 0; } Action: Initialize an entity of some type with the same type or compatible types. Or use appropriate cast operator to convert one operand to the other.
Action: Avoid such incompatible type conversions. Reference: C99 6.3.2.3 2167 argument of type %t1 is incompatible with parameter of type %t2 Cause: The parameter type passed is incompatible with the function argument type. Example: typedef char * addr; int foo(int a) { return a; } int main() { addr data = "0x1"; foo(data); return 0; } Action: Pass the parameter type that is compatible with the function argument type.
for(index; index < 10; index++){ } } Action: Modify the expression so that it has some effect or just remove it. 2175 subscript out of range Cause: The compiler has detected an array access that is outside the bounds of the array. The array access might cause unpredictable behavior. Example: int main() { int arr[10]; arr[10] = 20; } Action: Specify an array subscript that is within the bounds of the array type.
2181 argument is incompatible with corresponding format string conversion Cause: The compiler has detected a format specifier whose data type does not match its corresponding argument. Example: printf("%d", 2.0); Action: Modify either the argument or the conversion specifier so that they match. Reference:C99 6.2.2.7 2186 pointless comparison of unsigned integer with zero Cause: An unsigned expression is being tested to see if it is greater than zero.
Make sure that you do not mix enums and non-enums. Reference: 2191 type qualifier is meaningless on cast type Cause: Casting to a qualified type, though valid, is pointless. This is reported only when the cv-qualifiers are explicit in the cast,not, for example, when they are hidden in a typedef or template parameter type. Example: int i = (const volatile int) 10; Action: Remove the unnecessary qualifiers in the cast.
} Action: Declare the function before it is referenced. Reference: C99 6.5.2.2 2224 the format string requires additional arguments Cause: The number of conversion specifiers is more than the number of values to be converted as specified in the parameter list. Example:printf("%d %d", 2); Action: Make sure the number of conversion specifiers match the number of values to be converted.
Reference: C99 6.7.2.2 ANSI/ISO C++ 7.2 2231 declaration is not visible outside of function Cause: A type is declared within a function prototype. The type is local to the function prototype and will not be visible outside the prototype. This might cause unexpected errors later in the compilation. Example: void foo(struct X { int i; } ); Action: Declare the type before the function prototype.
Example: struct Dummy { int i; }; Dummy::i = 10; } Action: Access non-static members through objects only. For example: Dummy d; d.i = 10; Reference: 2248 pointer to reference is not allowed Cause: Pointer to reference is incorrect and is not allowed. Example: int *i = 0; int & * pri = i; } Action: Check if you meant to declare a pointer to a reference. For example: int * & pri = i; Reference: ANSI/ISO C++ 8.3.
Array of reference is incorrect and is not allowed. Example:int & iarr[5]; } Action: Remove the & and make it a plain array. For example: int iarr[5]; Reference: ANSI/ISO C++ 8.3.2 (4) 2252 reference %n requires an initializer Cause: Reference variables should always be initialized, unless the reference is declared as extern , or it is declared as a class member within a class declaration, or it is declared as a parameter or function return type.
Example: class A { private: int x; } c; c.x = 0; Action: Fix the access specifier of the member or the statement that is accessing the member. Reference: 2267 old-style parameter list (anachronism) Cause: The given function is defined using the old style K&R syntax. The C standard has marked this syntax as obsolescent, and it is not supported in C++. Consider using the standard C prototype syntax.
2278 a constructor or destructor may not return a value Cause: Constructors and destructors do not have a return type and they do not return any value. It is incorrect to provide a return statement for constructors and destructors. Example: struct Base { Base() { return 0; } }; Action: Remove the return statement, for example: Base() { } Reference: 2306 default argument not at end of parameter list Cause: Default arguments can only be provided at the end of the parameter list.
void foo(); }; const X s; s.foo(); } Action: Ensure that the cv qualifiers of the object are not stricter than cv qualifiers of the methods that called through it. Reference: ANSI/ISO C++ 9.3.2(4) 2319 pure specifier ("= 0") allowed only on virtual functions Cause: Only virtual functions can be declared as pure; other functions cannot have pure specifier as it is meaningless. Example: class base { public: static int foo() = 0; }; Action: Provide the pure specifier only for virtual functions.
Action: Initialize the member outside the class: int i = 100; class Init { static const int *p_i; }; const int* Init::p_i = Reference: ANSI/ISO C++ 9.4.2 9.2(4) 2322 object of abstract class type %t is not allowed Cause: By definition, objects of abstract types cannot be created; any such attempt will be flagged as an error by the compiler.
2329 local class member %n requires a definition Cause: Member functions of local classes must be defined within the class definition. Example: int main() { struct Struct { void foo(); }; Struct s; s.foo(); } Action: Define all required member functions of the local classes inside the class itself. Reference: ANSI/ISO C++ 9.8(2) 2336 unknown external linkage specification Cause: The linkage specification provided in the code is not known to this compiler implementation.
Example: static union { private: int i; protected: float f; }; Action: Provide public access to all the anonymous union members. For example: static union { public: int i; float f; }; Reference: ANSI/ISO C++ 9.5(3) 2364 invalid anonymous union -- member function is not allowed Cause: Anonynous unions cannot have member functions, they can only contain non-static data members. Example: static union { int foo() { return 0; } }; Action: Remove the member function from anonymous union.
2375 declaration requires a typedef name Cause: In a typedef declaration, the typedef name is missing. This case can occur when a declaration tries to declare both a tag and a typedef, but the name of the typedef is not included. Example: typedef int; Action: Either remove the typedef keyword or add a typedef name. Reference: 2381 extra ";" ignored Cause: An extra semicolon was found at the end of some code construct, which was perhaps added by mistake. It will be ignored.
Check if the assignment is required and if it is valid. If valid, use an explicit cast to force the assignment. Reference: 2546 transfer of control bypasses initialization of: "variable" Cause: Compiler has detected transfer of control was attempted that bypasses initialization of a variable.
2656 transfer of control into a try block Cause: Goto statements cannot be used to transfer control inside the try blocks. Example: goto LABEL; try { LABEL: throw 0; } catch(...) { } Action: Remove the goto statement that transfers the control inside the try block. Reference: ANSI/ISO C++ 15(2) 2767 conversion from pointer to smaller integer Cause: The 64-bit pointer is being cast to an integer type that is smaller in size. Casting a 64-bit pointer to a smaller integer type is undefined behavior.
Reference: 2830 %n has no corresponding operator delete%s (to be called if an exception is thrown during initialization of an allocated object) Cause: For operator new, a corresponding operator delete needs to be provided so that it can be called for proper destruction in case an exception is thrown during the initialization of the allocated object.
2940 missing return statement at end of non-void function "function" Cause: A function with an explicit return type does not contain a return statement. Example:int foo() { } Action: If the function is supposed to return a value, add a return statement with appropriate value, otherwise declare the return type as void. Reference: 2951 return type of function "main" must be int Cause: Standard C requires that the return type of "main" function must int.
Example:int foo(arg) { return arg; } Action: Declare the parameter. Preferable old-style function definitions should be replaced by prototype-format definitions. Reference: C99 6.9.1 3055 types cannot be declared in anonymous unions Cause: Anonynous unions can only define non-static data members. You cannot declare types or functions within anonymous unions. Example: static union { typedef int T; T i; }; Action: Remove the typedef from the anonymous union.
Action: #warning directives are usually added to warn against fallthrus in conditionally compiled code. check if you need to handle a new condition. Reference: 3138 format argument does not have string type Cause: The format argument of a function having same attributes as the printf, scanf family functions must be of string type. Example: int print(char *str,void *fmt, ...
3290 Passing a non-POD object to a function with variable arguments has undefined behavior. Object will be copied onto the stack instead of using a constructor. Cause: A non-POD (POD stands for "plain old data") object is being passed to a function with variable arguments. Object will be copied onto the stack instead of using a constructor.Varargs do not know how to deal with non-POD types, this can lead to undefined behavior. Example: class A { int i; }; int foo(char*, ...
void* operator new(unsigned long, void*) { return 0; } } object; Action: Provide a corresponding member operator delete to be called if an exception is thrown during the initialization of the allocated object. Reference: 3750 "\" followed by white space is not a line splice Cause: This warning is issued when a space is found after \ (backslash) at the end of line.
Disambiguate the expression by using explicit parenthesis around the bitwise operator, thus return ( p1 == (p2 | mask) ); Reference: 4227 padding struct with %s1 bytes to align member %sq2 Cause: The compiler has added s1 bytes before a member so that it will be aligned and hence accessed efficiently.
Reference: 4230 64 bit migration: conversion from %t1 to %t2 may cause target of pointers to have a different size. Cause: The compiler has detected conversion between pointers to data types having different sizes. This usually happens when assigning an int pointer to a long pointer or vice versa. This is not a problem in 32 bit mode since int, long and pointer all are of same size (32 bit) but in 64 bit mode int is 32 bit whereas long and pointer are 64 bit.
l = (long long*) p; // warning 4232 here } Action: Correct the code that uses such conversions. Reference: ANSI/ISO C++ 3.9, 3.9.1, 3.9.2 4235 conversion from %t1 to %t2 may lose significant bits Cause: The destination of an assignment has less range/precision than the source operand, this might cause a loss of value/precision. Example: int i = 10; double l = 10.345; int j = l/i; Action: Change the type of the destination or if the loss in significant bits is not a concern add a cast.
4241 redeclaration, function %nod was previously called without a prototype Cause: The switch expression type does not match with the type of case labels. Example: enum BOOLEAN { TRUE = 0, FALSE = 1 }; BOOLEAN a_bool = TRUE; switch(a_bool) { case 0: printf("true\n"); case 1: printf("false\n"); default: printf("no match found \n"); } Action: Fix your source code to ensure the type of the switch expression and case labels is same.
return 0; } Action: Remove the extern storage class specifier in function definition. Reference: 4245 storage class used with a data definition Cause: The compiler has detected the usage of an extern storage class specifier with a data definition. Example:extern int i = 1; Action: Remove the extern storage class specifier in the data definition. Reference: 4247 function called with different argument counts (%s vs.
The size of the result of an operation is determined based on the size of the operands and not based on the type into which the resultant value is being castled. If the result exceeds the size of the operands, in this case 32 bits, it will be truncated even before the cast takes place.
Example: typedef unsigned char uint8_t; typedef unsigned int uint32_t; int main() { struct X { uint32_t data_size; uint8_t status; }; } Action: Insertion of padding bytes themselves is not a problem but you need to ensure that you do not use hard coded offsets for accessing fields of the struct through pointers, use offset of macro instead. In some cases the number of padding bytes being inserted can be reduced by reordering the fields. Reference: ANSI/ISO C++ 18.
ANSI/ISO C++ 18.1(5) 4272 conversion from %t1 to %t2 may lose sign Cause: The Compiler has detected conversion from a signed data type to an unsigned data type. This may lead to loss of sign. Example: typedef unsigned int uint32_t; void foo(int j) { uint32_t k; k = j; } Action: If this is intended then add a cast.
Example: void foo(bool b, char c) { if (b == 3) { } // warning 4275 here if (c < 200) { } // warning 4275 here if ((unsigned char)c < 200) { } // no warning here } Action: Check the value of the constant being used in the operation. In the scenarios where the comparison is between signed and unsigned types the problem can be fixed by using a cast.
Action: Check if the constant is expected. In some cases the constant value might be the result of a valid macro expansion, in such scenarios you can suppress this warning for the particular macro using the +Wmacro option.
} object; Action: Declare the member functions to return a const handle instead. Reference: 4289 endian porting: the definition of the union may be endian dependent Cause: The values accessed using the members of a union may differ based on endianness of a machine in which the code is executed. This occurs when the union has members of different sizes, and when the value stored using one member is accessed using another of a different size.
Action: For portable code change the way these values are accessed. If the order in which the values are accessed is not important then first cast the pointer to void* type and then cast to the lesser integer type. Reference: 4295 abstract function type declared with empty parentheses, consider replacing with parameter list or void. Cause: The declaration of function has an empty parameter list.
Reference: 4300 Overflow while computing constant in left shift operation Cause: An overflow occurred while evaluating a constant in a left shift operation. Example: #define COUNT 24 #define ALPHA 0x0000EF int main() { int a = ALPHA << COUNT; } Action: Correct the constant expression so that it does not overflow. Reference: 4301 expression has no effect Cause: The expression has no effect or side-effect.
Check if you inadvertently inserted a ';'. Reference: 4354 One of the operands of the %sq operation is a string literal, strcmp() is recommended for such comparison Cause: If the character pointer is compared with a string literal, then the result is unspecified. char *ch_ptr = "hello"; if(ch_ptr == "world") { } Action: Use of '==' to compare 2 strings is unusual and might be done by mistake - check if you should be using strcmp() instead.
const char *ch0 = "\028\4471"; return 0; } Action: For example: "\028" - Here '8' follows escape sequence '\02'. You can change the string to "\02" "8". Reference: 4360 size of types of consecutive bitfields are different, bitfield packing behavior may be different across compiler Cause: This warning is issued during bitfield packing when the types in the structure are different. Example: #include
It is good to use similar types for bitfield packing. This is because, bitfield packing behavior might be different across compilers. Reference: 4363 possible mismatch in parameters passed to %n, previously seen %p Cause: During compilation of C programs, when a function is called without prototype, the compiler is unaware of the exact parameter types. It tries to fetch this information from the actual parameters being passed in the call.
The values accessed using the members of a union may differ based on endianness of a machine in which the code is executed. This occurs when the union has members of different sizes, and when the value stored using one member is accessed using another of a different size. Example: #include union endian { short s; int i; char c;}; int main() { union endian u; u.i = 0x01234567; printf("%hx\n", u.s); return 0; } cadvise displays the following warning when the option +Ww4365 is passed to it.
int main() { int i; time_t t1 = 1024; scanf("%d", ); if (t1+=i, t1 < 10) { t1 *= i; } return 0; } The expressions t1 += i, and t1 *= i can cause overflow and needs to be explicitly checked. Action: If there is no explicit check for overflow after arithmetic expressions on time_t/clock_t values, add a check.
4378 endian porting: accessing data without conversion may be endian dependent Cause: After receiving data from the remote socket to host system, it should be converted from network to host byte order to ensure correctness of the data. This diagnostic occurs when the data, 1. received from network/other system is not converted using pre-defined conversion calls such as ntohs/ntohl or 2. modified before usage but after the conversion.
Action: Initialize the reported variable with a value before it is used. This may not be the only use of the uninitialized value. So it is best to initialize variables as close as possible to the point of declaration. Reference: 20036 variable %s (field %s) is used before its value is set Cause: The compiler has detected use of a member of a struct variable before it's value is set. Example: struct foo { int a; int b; }; int func() { struct foo x; x.a = x.
-- file1.c ---typedef struct { int f; int g; } A; A global; // LINE 6 void print_A(A par) // LINE 8 { printf("%d %d", par.f, par.g); } -- file2.c ---typedef struct { int f; char g; // Should be: int g; } A; A global; void print_A(A); main() { print_A(global); } "file1.c", line 8: warning #20048-D: Function "print_A" has incompatible type with previous declaration at line 8 in file "file2.c" "file2.
Reference: 20074 variable %s (field "%s") may be used before its value is set Cause: A field of a struct may be referenced prior to its initialization. Example: struct A { int a; int b; }; struct A a; a.a = 10; if (cond) a.b = 12; foo(a); // warning 20074: field b of struct a may // be uninitialized. Action: Ensure that all fields of a struct are unconditionally initialized prior to accessing them.
#include #include int leak1 (int k) { char *p = malloc (k); // LINE 6 strcpy (p, "hello"); printf ("%s", p); return 0; } "memleak.c", line 6, procedure leak1: warning #20201-D: Memory leak is detected. Action: Make sure that the pointer allocated at the location mentioned in the diagnostic is freed correctly. Reference: 20202 Allocated memory may potentially be leaked %s Cause: A memory leak may occur for the memory allocation done at the location mentioned in the message.
} int main() { int result = foo(); return result; } "oos.c", line 11, procedure foo: warning #20203-D: Potential out of scope use of local variable q Action: Check that the local variable mentioned in the diagnostic does not have its address taken and returned to the caller function or an allocated memory pointer is not returned to the caller. Reference: 20206 Out of bound access (%s) Cause: The expression is accessing out of object's memory boundary.
} line 7, procedure foo: warning #20208-D: Forming out of bound address (In expression "&buf[0]+20", variable "buf" [test.c:1] (type: char [12]) has byte range [0 .. 11], forming address byte [20].) Action: Fix the forming out of bounds access if it is a real bug. Reference: 20210 Mismatch in allocation and deallocation Cause: The compiler has detected a code that uses different methods for memory allocation and it's corresponding deallocation.
s = (char*) malloc(128); if (s == 0) exit(1); } sprintf(s,"%d",x); puts(s); // LINE 25 } line 9, procedure mod_astring: warning #20213-D: Potential write to readonly memory through astring is detected line 25, procedure possible: warning #20213-D: Potential write to readonly memory through s is detected Action: Look at the definition of the memory written to and make sure that it is not defined as "const".
{ foo2(5); return 0; } Action: Ensure that all elements or fields of an array or struct are unconditionally initialized prior to accessing them.