/* Bounded attribute types */
enum bounded_type { buffer_bound_type, string_bound_type,
minbytes_bound_type, size_bound_type,
- bounded_type_error };
+ bounded_type_error, wcstring_bound_type };
typedef struct bound_check_info
{
if (info.bounded_type == size_bound_type
|| info.bounded_type == string_bound_type
- || info.bounded_type == buffer_bound_type)
+ || info.bounded_type == buffer_bound_type
+ || info.bounded_type == wcstring_bound_type)
{
arg_iterate = argument;
for (arg_num = 1; ; ++arg_num)
return false;
}
break;
+ case wcstring_bound_type:
+ if (bounded_size_expr)
+ warning (
+ OPT_Wbounded, "`wcstring' bound type only takes 2 parameters");
+ bounded_size_expr = size_int (0);
+ break;
}
/* Strip any conversions from the buffer parameters and verify they
return minbytes_bound_type;
else if (!strcmp (s, "size") || !strcmp (s, "__size__"))
return size_bound_type;
+ else if (!strcmp (s, "wcstring") || !strcmp (s, "__wcstring__"))
+ return wcstring_bound_type;
else
return bounded_type_error;
}
status_warning(status, "array size (%d) smaller than required length (%d * %d)",
array_size, length, elem_size);
break;
+ case wcstring_bound_type:
+ /* warn about illegal bounds value */
+ if (length < 0)
+ status_warning (
+ status, "non-positive bounds length (%d) detected", length);
+ /* check if the static buffer is smaller than bound length */
+ if (array_size / type_size < length)
+ status_warning(status, "array size (%d) smaller than bound length"
+ " (%d) * sizeof(type)", array_size, length);
+ break;
}
}
}
/* Bounded attribute types */
enum bounded_type { buffer_bound_type, string_bound_type,
minbytes_bound_type, size_bound_type,
- bounded_type_error };
+ bounded_type_error, wcstring_bound_type };
typedef struct bound_check_info
{
if (info.bounded_type == size_bound_type
|| info.bounded_type == string_bound_type
- || info.bounded_type == buffer_bound_type)
+ || info.bounded_type == buffer_bound_type
+ || info.bounded_type == wcstring_bound_type)
{
arg_iterate = argument;
for (arg_num = 1; ; ++arg_num)
return false;
}
break;
+ case wcstring_bound_type:
+ if (bounded_size_expr)
+ warning ("`wcstring' bound type only takes 2 parameters");
+ bounded_size_expr = size_int (0);
+ break;
}
/* Strip any conversions from the buffer parameters and verify they
return minbytes_bound_type;
else if (!strcmp (s, "size") || !strcmp (s, "__size__"))
return size_bound_type;
+ else if (!strcmp (s, "wcstring") || !strcmp (s, "__wcstring__"))
+ return wcstring_bound_type;
else
return bounded_type_error;
}
STRIP_NOPS (buf_expr);
/* Check for a possible sizeof(pointer) error in string functions */
- if (info->bounded_type == string_bound_type
+ if ((info->bounded_type == string_bound_type
+ || info->bounded_type == wcstring_bound_type)
&& SIZEOF_PTR_DERIVED (length_expr))
status_warning(status, "sizeof(pointer) possibly incorrect in argument %d",
info->bounded_num);
status_warning(status, "array size (%d) smaller than required length (%d * %d)",
array_size, length, elem_size);
break;
+ case wcstring_bound_type:
+ /* warn about illegal bounds value */
+ if (length < 0)
+ status_warning (
+ status, "non-positive bounds length (%d) detected", length);
+ /* check if the static buffer is smaller than bound length */
+ if (array_size / type_size < length)
+ status_warning(status, "array size (%d) smaller than bound length"
+ " (%d) * sizeof(type)", array_size, length);
+ break;
}
}
}