[apparmor] [PATCH v2 44/42] libapparmor: Remove casts while allocating memory
John Johansen
john.johansen at canonical.com
Tue Mar 24 21:26:13 UTC 2015
On 03/24/2015 11:06 AM, Tyler Hicks wrote:
> The libapparmor library is built with gcc, while the parser is built
> with g++. The parser code needs to cast pointers returned from the
> malloc(3) family of calls. However, code removed from the parser to
> libapparmor can drop the casts.
>
> Signed-off-by: Tyler Hicks <tyhicks at canonical.com>
Acked-by: John Johansen <john.johansen at canonical.com>
> ---
> libraries/libapparmor/src/features.c | 4 ++--
> libraries/libapparmor/src/grammar.y | 2 +-
> libraries/libapparmor/src/kernel_interface.c | 4 ++--
> libraries/libapparmor/src/policy_cache.c | 2 +-
> 4 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/libraries/libapparmor/src/features.c b/libraries/libapparmor/src/features.c
> index 4a70475..88ded73 100644
> --- a/libraries/libapparmor/src/features.c
> +++ b/libraries/libapparmor/src/features.c
> @@ -353,7 +353,7 @@ int aa_features_new(aa_features **features, const char *path)
> if (stat(path, &stat_file) == -1)
> return -1;
>
> - f = (aa_features *) calloc(1, sizeof(*f));
> + f = calloc(1, sizeof(*f));
> if (!f) {
> errno = ENOMEM;
> return -1;
> @@ -397,7 +397,7 @@ int aa_features_new_from_string(aa_features **features,
> if (size >= STRING_SIZE)
> return ENOBUFS;
>
> - f = (aa_features *) calloc(1, sizeof(*f));
> + f = calloc(1, sizeof(*f));
> if (!f) {
> errno = ENOMEM;
> return -1;
> diff --git a/libraries/libapparmor/src/grammar.y b/libraries/libapparmor/src/grammar.y
> index 66b3984..56d4328 100644
> --- a/libraries/libapparmor/src/grammar.y
> +++ b/libraries/libapparmor/src/grammar.y
> @@ -418,7 +418,7 @@ _parse_yacc(char *str)
> int parser_return;
>
> ret_record = NULL;
> - ret_record = (aa_log_record *) malloc(sizeof(aa_log_record));
> + ret_record = malloc(sizeof(aa_log_record));
>
> _init_log_record(ret_record);
>
> diff --git a/libraries/libapparmor/src/kernel_interface.c b/libraries/libapparmor/src/kernel_interface.c
> index f142b8d..24239ce 100644
> --- a/libraries/libapparmor/src/kernel_interface.c
> +++ b/libraries/libapparmor/src/kernel_interface.c
> @@ -159,7 +159,7 @@ static int write_policy_fd_to_iface(aa_kernel_interface *kernel_interface,
>
> do {
> if (asize - size == 0) {
> - buffer = (char *) realloc(buffer, chunksize);
> + buffer = realloc(buffer, chunksize);
> asize = chunksize;
> chunksize <<= 1;
> if (!buffer) {
> @@ -213,7 +213,7 @@ int aa_kernel_interface_new(aa_kernel_interface **kernel_interface,
>
> *kernel_interface = NULL;
>
> - ki = (aa_kernel_interface *) calloc(1, sizeof(*ki));
> + ki = calloc(1, sizeof(*ki));
> if (!ki) {
> errno = ENOMEM;
> return -1;
> diff --git a/libraries/libapparmor/src/policy_cache.c b/libraries/libapparmor/src/policy_cache.c
> index d9ec4a1..98155a6 100644
> --- a/libraries/libapparmor/src/policy_cache.c
> +++ b/libraries/libapparmor/src/policy_cache.c
> @@ -149,7 +149,7 @@ int aa_policy_cache_new(aa_policy_cache **policy_cache,
> return -1;
> }
>
> - pc = (aa_policy_cache *) calloc(1, sizeof(*pc));
> + pc = calloc(1, sizeof(*pc));
> if (!pc) {
> errno = ENOMEM;
> return -1;
>
More information about the AppArmor
mailing list