← Back to team overview

hipl-core team mailing list archive

Re: [Branch ~hipl-core/hipl/trunk] Rev 4898: Fixed 'cast discards qualifiers' warnings in hip_get_next_param()

 

On Thu, Aug 19, 2010 at 09:34:25AM +0000, noreply@xxxxxxxxxxxxx wrote:
> ------------------------------------------------------------
> revno: 4898
> committer: Artturi Karila <artturi.karila@xxxxxxxxxx>
> branch nick: trunk
> timestamp: Thu 2010-08-19 12:32:20 +0300
> message:
>   Fixed 'cast discards qualifiers' warnings in hip_get_next_param()
>   
> --- firewall/conntrack.c	2010-08-18 16:21:16 +0000
> +++ firewall/conntrack.c	2010-08-19 09:32:20 +0000
> @@ -925,10 +925,12 @@
>      // store the public key separately
>      // store function pointer for verification
>      if (hip_get_host_id_algo(tuple->hip_tuple->data->src_hi) == HIP_HI_RSA) {
> -        tuple->hip_tuple->data->src_pub_key = hip_key_rr_to_rsa((struct hip_host_id_priv *) host_id, 0);
> +        tuple->hip_tuple->data->src_pub_key = hip_key_rr_to_rsa(
> +                                 (const struct hip_host_id_priv *) host_id, 0);

Breaking functions at the opening parenthesis looks ugly IMO.

  tuple->hip_tuple->data->src_pub_key =
      hip_key_rr_to_rsa((const struct hip_host_id_priv *) host_id, 0);

would look better IMO.

>          tuple->hip_tuple->data->verify      = hip_rsa_verify;
>      } else {
> -        tuple->hip_tuple->data->src_pub_key = hip_key_rr_to_dsa((struct hip_host_id_priv *) host_id, 0);
> +        tuple->hip_tuple->data->src_pub_key = hip_key_rr_to_dsa(
> +                                 (const struct hip_host_id_priv *) host_id, 0);

same

> @@ -996,10 +998,12 @@
>          // store the public key separately
>          // store function pointer for verification
>          if (hip_get_host_id_algo(tuple->hip_tuple->data->src_hi) == HIP_HI_RSA) {
> -            tuple->hip_tuple->data->src_pub_key = hip_key_rr_to_rsa((struct hip_host_id_priv *) host_id, 0);
> +            tuple->hip_tuple->data->src_pub_key = hip_key_rr_to_rsa(
> +                                 (const struct hip_host_id_priv *) host_id, 0);
>              tuple->hip_tuple->data->verify      = hip_rsa_verify;
>          } else {
> -            tuple->hip_tuple->data->src_pub_key = hip_key_rr_to_dsa((struct hip_host_id_priv *) host_id, 0);
> +            tuple->hip_tuple->data->src_pub_key = hip_key_rr_to_dsa(
> +                                 (const struct hip_host_id_priv *) host_id, 0);
>              tuple->hip_tuple->data->verify      = hip_dsa_verify;
>          }
>  

more - and there are other instances below.

> --- firewall/esp_prot_fw_msg.c	2010-08-18 17:57:40 +0000
> +++ firewall/esp_prot_fw_msg.c	2010-08-19 09:32:20 +0000
> @@ -627,12 +627,12 @@
>  
>          HIP_IFEL(!(param = hip_get_param(msg, HIP_PARAM_ITEM_LENGTH)),
>                   -1, "transform suggests hash_item_length, but it is NOT included in msg\n");
> -        *hash_item_length = *((uint32_t *) hip_get_param_contents_direct(param));
> +        *hash_item_length = *((const uint32_t *) hip_get_param_contents_direct(param));

Far too many of these casts exist.  We should be able to avoid them if the
variable is declared as a pointer directly.

> --- hipd/cert.c	2010-08-10 07:24:52 +0000
> +++ hipd/cert.c	2010-08-19 09:32:20 +0000
> @@ -734,14 +734,10 @@
>  
> -    HIP_IFEL(!(subject = malloc(sizeof(struct in6_addr))), -1,
> -             "Malloc for subject failed\n");
>      HIP_IFEL(!(issuer_hit_n = malloc(sizeof(struct in6_addr))), -1,
>               "Malloc for subject failed\n");
>      HIP_IFEL(!(pkey = malloc(sizeof(EVP_PKEY))), -1,
>               "Malloc for pkey failed\n");
> -    HIP_IFEL(!memset(subject, 0, sizeof(subject)), -1,
> -             "Failed to memset memory for subject\n");
>      HIP_IFEL(!memset(issuer_hit_n, 0, sizeof(issuer_hit_n)), -1,
>               "Failed to memset memory for issuer\n");

This is related to the commit, how?

> --- hipd/hadb.c	2010-08-17 17:23:18 +0000
> +++ hipd/hadb.c	2010-08-19 09:32:20 +0000
> @@ -618,22 +620,18 @@
> -    hit           = (struct in6_addr *)
> -                    hip_get_param_contents(input, HIP_PARAM_HIT);
> -
> -    lsi           = (hip_lsi_t *)
> -                    hip_get_param_contents(input, HIP_PARAM_LSI);
> -
> -    ip            = (struct in6_addr *)
> -                    hip_get_param_contents(input, HIP_PARAM_IPV6_ADDR);
> -
> -    peer_hostname = (char *)
> -                    hip_get_param_contents(input, HIP_PARAM_HOSTNAME);
> +
> +    hit           = hip_get_param_contents(input, HIP_PARAM_HIT);
> +
> +    lsi           = hip_get_param_contents(input, HIP_PARAM_LSI);
> +
> +    ip            = hip_get_param_contents(input, HIP_PARAM_IPV6_ADDR);
> +
> +    peer_hostname = hip_get_param_contents(input, HIP_PARAM_HOSTNAME);

These cast removals are correct, but unrelated.

> --- hipd/hidb.c	2010-07-29 10:40:44 +0000
> +++ hipd/hidb.c	2010-08-19 09:32:20 +0000
> @@ -600,13 +600,12 @@
>  
> -    hit = (struct in6_addr *)
> -          hip_get_param_contents(input, HIP_PARAM_HIT);
> +    hit = hip_get_param_contents(input, HIP_PARAM_HIT);

more

> --- hipd/hiprelay.c	2010-08-18 16:30:31 +0000
> +++ hipd/hiprelay.c	2010-08-19 09:32:20 +0000
> @@ -1118,15 +1118,14 @@
>      case HIP_R2:
>      case HIP_UPDATE:
>      case HIP_NOTIFY:
> -        HIP_DEBUG_IN6ADDR("the relay to address: ",
> -                          (struct in6_addr *) &relay_to->address);
> +        HIP_DEBUG_IN6ADDR("the relay to address: ", &relay_to->address);
>          HIP_DEBUG("the relay to ntohs(port): %d",
>                    ntohs(relay_to->port));
>          hip_relay_forward_response(ctx->input_msg,
>                                     packet_type,
>                                     ctx->src_addr,
>                                     ctx->dst_addr,
> -                                   (struct in6_addr *) &relay_to->address,
> +                                   &relay_to->address,
>                                     ntohs(relay_to->port));

unrelated

> @@ -1146,14 +1145,13 @@
>   *
>   * @todo handle also the relay case
>   */
> -int hip_relay_add_rvs_to_ha(hip_common_t *source_msg, hip_ha_t *entry)
> +int hip_relay_add_rvs_to_ha(const hip_common_t *source_msg, hip_ha_t *entry)
>  {
> -    struct hip_via_rvs *via_rvs = NULL;
> +    const struct hip_via_rvs *via_rvs = NULL;
>      int err                     = 0;
>  
>      // Get rendezvous server's IP addresses
> -    via_rvs = (struct hip_via_rvs *)
> -              hip_get_param(source_msg, HIP_PARAM_VIA_RVS);
> +    via_rvs = hip_get_param(source_msg, HIP_PARAM_VIA_RVS);

more

> @@ -1312,13 +1310,11 @@
>      switch (packet_type) {
>      case HIP_R1:
>      case HIP_R2:
> -        HIP_DEBUG_IN6ADDR("the relay to address: ",
> -                          (struct in6_addr *) &relay_to->address);
> +        HIP_DEBUG_IN6ADDR("the relay to address: ", &relay_to->address);
>          HIP_DEBUG("the relay to ntohs(port): %d, local udp port %d\n",
>                    ntohs(relay_to->port), ctx->hadb_entry->local_udp_port);
>  
> -        if (ipv6_addr_cmp((struct in6_addr *) &relay_to->address,
> -                          &ctx->hadb_entry->our_addr)) {
> +        if (ipv6_addr_cmp(&relay_to->address, &ctx->hadb_entry->our_addr)) {

again

> --- hipd/output.c	2010-08-17 17:23:18 +0000
> +++ hipd/output.c	2010-08-19 09:32:20 +0000
> @@ -338,8 +339,8 @@
>                       -1,
>                       "Building of param encrypted failed.\n");
> -            enc_in_msg     = hip_get_param(ctx->output_msg,
> -                                           HIP_PARAM_ENCRYPTED);
> +            enc_in_msg     = hip_get_param_readwrite(ctx->output_msg,
> +                                                    HIP_PARAM_ENCRYPTED);

Indentation is off.

> --- hipd/registration.c	2010-07-07 16:42:17 +0000
> +++ hipd/registration.c	2010-08-19 09:32:20 +0000
> @@ -1378,8 +1382,8 @@
>          /* Iterate to the next parameter and break the loop if there are
>           * no more parameters left. */
>          i          = 0;
> -        reg_failed = (struct hip_reg_failed *)
> -                     hip_get_next_param(msg, (hip_tlv_common_t *) reg_failed);
> +        reg_failed = (const struct hip_reg_failed *) hip_get_next_param(msg,
> +                                        (const hip_tlv_common_t *) reg_failed);

Indentation is off.

> --- hipd/user.c	2010-08-18 16:30:31 +0000
> +++ hipd/user.c	2010-08-19 09:32:20 +0000
> @@ -885,8 +885,9 @@
>      {
>          err = 0;
>          struct hip_hit_to_ip_set *name_info;
> -        HIP_IFEL(!(name_info = hip_get_param(msg, HIP_PARAM_HIT_TO_IP_SET)), -1,
> -                 "no name struct found\n");
> +        HIP_IFEL(!(name_info = hip_get_param_readwrite(msg, 
> +                                                     HIP_PARAM_HIT_TO_IP_SET)),
> +                 -1, "no name struct found\n");

Indentation is off.

> --- lib/core/debug.c	2010-07-29 13:27:02 +0000
> +++ lib/core/debug.c	2010-08-19 09:32:20 +0000
> @@ -680,34 +680,37 @@
> -void hip_print_locator_addresses(struct hip_common *in_msg)
> +void hip_print_locator_addresses(const struct hip_common *in_msg)
>  {
> -    struct hip_locator *locator;
> -    struct hip_locator_info_addr_item *item   = NULL;
> -    struct hip_locator_info_addr_item2 *item2 = NULL;
> -    char *address_pointer;
> +    const struct hip_locator *locator;
> +    const struct hip_locator_info_addr_item *ptr    = NULL;
> +    const struct hip_locator_info_addr_item *item   = NULL;
> +    const struct hip_locator_info_addr_item2 *item2 = NULL;
> +    const char *address_pointer;
>  
> -    locator = hip_get_param((struct hip_common *) in_msg,
> -                            HIP_PARAM_LOCATOR);
> +    locator = hip_get_param(in_msg, HIP_PARAM_LOCATOR);

unrelated cast removal

> --- lib/core/solve.h	2010-07-14 16:01:50 +0000
> +++ lib/core/solve.h	2010-08-19 09:32:20 +0000
> @@ -34,7 +34,8 @@
>  
> -uint64_t hip_solve_puzzle(void *puzzle, struct hip_common *hdr, int mode);
> +uint64_t hip_solve_puzzle(const void *puzzle, 
> +                          const struct hip_common *hdr, int mode);

trailing whitespace

Diego



References