diff options
author | Martynas Venckus <martynas@cvs.openbsd.org> | 2014-01-14 22:26:31 +0000 |
---|---|---|
committer | Martynas Venckus <martynas@cvs.openbsd.org> | 2014-01-14 22:26:31 +0000 |
commit | 91c44e3ea297825ce56fa2c9ecfd74257e131c43 (patch) | |
tree | c8a8b81cb0e5cc97f008e9f1048cca54aae21c1b | |
parent | 23b2746ea3f90ca857d4fd5387efa24da174355c (diff) |
Add wcstring attribute support for Wbounded. To be used for wchar.h
which operates on element counts rather than buffer sizes. I'll start
annotating headers in a few weeks, after the hackathon. OK millert@.
-rw-r--r-- | gnu/gcc/gcc/c-bounded.c | 23 | ||||
-rw-r--r-- | gnu/usr.bin/gcc/gcc/c-bounded.c | 25 |
2 files changed, 43 insertions, 5 deletions
diff --git a/gnu/gcc/gcc/c-bounded.c b/gnu/gcc/gcc/c-bounded.c index 63f6fe0a025..5a3916b60ed 100644 --- a/gnu/gcc/gcc/c-bounded.c +++ b/gnu/gcc/gcc/c-bounded.c @@ -34,7 +34,7 @@ /* 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 { @@ -101,7 +101,8 @@ handle_bounded_attribute (node, name, args, flags, no_add_attrs) 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) @@ -213,6 +214,12 @@ decode_bounded_attr (args, info, validated_p) 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 @@ -291,6 +298,8 @@ decode_bounded_type (s) 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; } @@ -485,6 +494,16 @@ check_bounded_info (status, info, params) 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; } } } diff --git a/gnu/usr.bin/gcc/gcc/c-bounded.c b/gnu/usr.bin/gcc/gcc/c-bounded.c index fcfaeba889e..f13d74e549a 100644 --- a/gnu/usr.bin/gcc/gcc/c-bounded.c +++ b/gnu/usr.bin/gcc/gcc/c-bounded.c @@ -31,7 +31,7 @@ /* 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 { @@ -98,7 +98,8 @@ handle_bounded_attribute (node, name, args, flags, no_add_attrs) 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) @@ -209,6 +210,11 @@ decode_bounded_attr (args, info, validated_p) 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 @@ -287,6 +293,8 @@ decode_bounded_type (s) 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; } @@ -406,7 +414,8 @@ check_bounded_info (status, info, params) 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); @@ -488,6 +497,16 @@ check_bounded_info (status, info, params) 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; } } } |