HP-UX Cadvise Diagnostics Reference Guide (5900-1865, August 2012)

Table Of Contents
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:
void foo(int data) {
long data1 = (long) (data << 16); // warning 4249 here
long data2 = ((long)data) << 16; // no warning
}
Action:
If you expect the value of the result to exceed the size of the type of operands then cast the operands
to the bigger type before the operation.
Reference:
4251 the assignment has an excessive size for a bit field
Cause:
The constant has a larger value than that can be stored in the bit-field.
Example:
struct A {
unsigned int f1 : 1;
};
int main() {
A obj;
obj.f1 = 30;
}
Action:
Ensure that the assigned value is within the range of the values that the bit-field can store.
Reference:
4253 unsigned value cannot be less than zero
Cause:
An ordered comparison between an unsigned value and a constant that is less than or equal to
zero often indicates a programming error. A negative value is converted to an unsigned value
before the comparison, so any negative value compares larger than most unsigned values. If the
code is correct, the comparison could be more clearly coded by testing for equality with zero.
Example:
int main() {
unsigned data = 30;
if(data <= 0)
return 1;
}
Action:
Cast (or otherwise rewrite) one of the operands of the compare to match the signedness of the
other operand, or compare for equality with zero.
Reference:
4255 padding size of struct %sq1 with %s2 bytes to alignment boundary
Cause:
Padding bytes have been inserted for proper alignment of the struct.
58 Diagnostics Details