Remaining "cast"/"const" patches

Andrew Bartlett abartlet at samba.org
Tue Oct 27 17:43:37 MDT 2009


On Sun, 2009-10-18 at 16:25 +0000, Matthias Dieter Wallnöfer wrote:
> Andrew,
> 
> I finished the split-up. It's not reasonable to post the patches as attachment - so they're only in my private repo. Maybe you like to write the filenames or patch titles of those which look okay.

On another of the patches:

This patch looks reasonable - almost:

> index b6cc410..727470c 100644
> @@ -418,29 +418,29 @@ static WERROR
> gp_extension_store_reg_vals(TALLOC_CTX *mem_ctx,
> ****************************************************************/
> 
> static WERROR gp_extension_store_reg_entry(TALLOC_CTX *mem_ctx,
>    struct gp_registry_context *reg_ctx,
>    struct gp_extension_reg_info_entry *entry)
> {
> WERROR werr;
> struct registry_key *key = NULL;
> - const char *subkeyname = NULL;
> + char *subkeyname = NULL;
> 
> if (!gp_extension_reg_info_verify(entry)) {
> return WERR_INVALID_PARAM;
> }
> 
> subkeyname = GUID_string2(mem_ctx, &entry->guid);
> W_ERROR_HAVE_NO_MEMORY(subkeyname);
> 
> - strupper_m(CONST_DISCARD(char *,subkeyname));
> + strupper_m(subkeyname);
> 
> werr = gp_store_reg_subkey(mem_ctx,
> -    subkeyname,
> +    (const char *) subkeyname,

Perhaps I don't know the code, but why do you need to add a cast here?

>    reg_ctx->curr_key,
>    &key);
> W_ERROR_NOT_OK_RETURN(werr);
> 
> werr = gp_extension_store_reg_vals(mem_ctx,
>    key,
>    entry);
> W_ERROR_NOT_OK_RETURN(werr);

As a rule, you should add as few casts as possible.  There are plenty of
cases where they are required due to signed/unsigned warnings, but every
cast is a potential bug in the future, as it overrides the compilers
ability to warn about other things.

Andrew Bartlett

-- 
Andrew Bartlett                                http://samba.org/~abartlet/
Authentication Developer, Samba Team           http://samba.org
Samba Developer, Cisco Inc.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20091028/749fe15a/attachment.pgp>


More information about the samba-technical mailing list