All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] slirp: Remove some type casts caused by bad declaration of x.tp_buf
@ 2011-02-23 18:40 Stefan Weil
  2011-02-25 18:07 ` Blue Swirl
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Weil @ 2011-02-23 18:40 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: qemu-devel

x.tp_buf was declared as a uint8_t array, but always used as
a char array (which needed a lot of type casts).

The patch includes these changes:

* Fix declaration of x.tp_buf and remove all type casts.

* Use offsetof() to get the offset of x.tp_buf.

Signed-off-by: Stefan Weil <weil@mail.berlios.de>
---
 slirp/tftp.c |   14 +++++++-------
 slirp/tftp.h |    2 +-
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/slirp/tftp.c b/slirp/tftp.c
index 1821648..8055ccc 100644
--- a/slirp/tftp.c
+++ b/slirp/tftp.c
@@ -136,9 +136,9 @@ static int tftp_send_oack(struct tftp_session *spt,
     m->m_data += sizeof(struct udpiphdr);
 
     tp->tp_op = htons(TFTP_OACK);
-    n += snprintf((char *)tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%s",
+    n += snprintf(tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%s",
                   key) + 1;
-    n += snprintf((char *)tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%u",
+    n += snprintf(tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%u",
                   value) + 1;
 
     saddr.sin_addr = recv_tp->ip.ip_dst;
@@ -283,7 +283,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
 
   /* skip header fields */
   k = 0;
-  pktlen -= ((uint8_t *)&tp->x.tp_buf[0] - (uint8_t *)tp);
+  pktlen -= offsetof(struct tftp_t, x.tp_buf);
 
   /* prepend tftp_prefix */
   prefix_len = strlen(slirp->tftp_prefix);
@@ -299,7 +299,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
       tftp_send_error(spt, 2, "Access violation", tp);
       return;
     }
-    req_fname[k] = (char)tp->x.tp_buf[k];
+    req_fname[k] = tp->x.tp_buf[k];
     if (req_fname[k++] == '\0') {
       break;
     }
@@ -311,7 +311,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
     return;
   }
 
-  if (strcasecmp((const char *)&tp->x.tp_buf[k], "octet") != 0) {
+  if (strcasecmp(&tp->x.tp_buf[k], "octet") != 0) {
       tftp_send_error(spt, 4, "Unsupported transfer mode", tp);
       return;
   }
@@ -340,7 +340,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
   while (k < pktlen) {
       const char *key, *value;
 
-      key = (const char *)&tp->x.tp_buf[k];
+      key = &tp->x.tp_buf[k];
       k += strlen(key) + 1;
 
       if (k >= pktlen) {
@@ -348,7 +348,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
 	  return;
       }
 
-      value = (const char *)&tp->x.tp_buf[k];
+      value = &tp->x.tp_buf[k];
       k += strlen(value) + 1;
 
       if (strcasecmp(key, "tsize") == 0) {
diff --git a/slirp/tftp.h b/slirp/tftp.h
index b9f0847..72e5e91 100644
--- a/slirp/tftp.h
+++ b/slirp/tftp.h
@@ -26,7 +26,7 @@ struct tftp_t {
       uint16_t tp_error_code;
       uint8_t tp_msg[512];
     } tp_error;
-    uint8_t tp_buf[512 + 2];
+    char tp_buf[512 + 2];
   } x;
 };
 
-- 
1.7.2.3

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH] slirp: Remove some type casts caused by bad declaration of x.tp_buf
  2011-02-23 18:40 [Qemu-devel] [PATCH] slirp: Remove some type casts caused by bad declaration of x.tp_buf Stefan Weil
@ 2011-02-25 18:07 ` Blue Swirl
  0 siblings, 0 replies; 2+ messages in thread
From: Blue Swirl @ 2011-02-25 18:07 UTC (permalink / raw)
  To: Stefan Weil; +Cc: Anthony Liguori, qemu-devel

Thanks, applied.

On Wed, Feb 23, 2011 at 8:40 PM, Stefan Weil <weil@mail.berlios.de> wrote:
> x.tp_buf was declared as a uint8_t array, but always used as
> a char array (which needed a lot of type casts).
>
> The patch includes these changes:
>
> * Fix declaration of x.tp_buf and remove all type casts.
>
> * Use offsetof() to get the offset of x.tp_buf.
>
> Signed-off-by: Stefan Weil <weil@mail.berlios.de>
> ---
>  slirp/tftp.c |   14 +++++++-------
>  slirp/tftp.h |    2 +-
>  2 files changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/slirp/tftp.c b/slirp/tftp.c
> index 1821648..8055ccc 100644
> --- a/slirp/tftp.c
> +++ b/slirp/tftp.c
> @@ -136,9 +136,9 @@ static int tftp_send_oack(struct tftp_session *spt,
>     m->m_data += sizeof(struct udpiphdr);
>
>     tp->tp_op = htons(TFTP_OACK);
> -    n += snprintf((char *)tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%s",
> +    n += snprintf(tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%s",
>                   key) + 1;
> -    n += snprintf((char *)tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%u",
> +    n += snprintf(tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%u",
>                   value) + 1;
>
>     saddr.sin_addr = recv_tp->ip.ip_dst;
> @@ -283,7 +283,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
>
>   /* skip header fields */
>   k = 0;
> -  pktlen -= ((uint8_t *)&tp->x.tp_buf[0] - (uint8_t *)tp);
> +  pktlen -= offsetof(struct tftp_t, x.tp_buf);
>
>   /* prepend tftp_prefix */
>   prefix_len = strlen(slirp->tftp_prefix);
> @@ -299,7 +299,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
>       tftp_send_error(spt, 2, "Access violation", tp);
>       return;
>     }
> -    req_fname[k] = (char)tp->x.tp_buf[k];
> +    req_fname[k] = tp->x.tp_buf[k];
>     if (req_fname[k++] == '\0') {
>       break;
>     }
> @@ -311,7 +311,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
>     return;
>   }
>
> -  if (strcasecmp((const char *)&tp->x.tp_buf[k], "octet") != 0) {
> +  if (strcasecmp(&tp->x.tp_buf[k], "octet") != 0) {
>       tftp_send_error(spt, 4, "Unsupported transfer mode", tp);
>       return;
>   }
> @@ -340,7 +340,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
>   while (k < pktlen) {
>       const char *key, *value;
>
> -      key = (const char *)&tp->x.tp_buf[k];
> +      key = &tp->x.tp_buf[k];
>       k += strlen(key) + 1;
>
>       if (k >= pktlen) {
> @@ -348,7 +348,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
>          return;
>       }
>
> -      value = (const char *)&tp->x.tp_buf[k];
> +      value = &tp->x.tp_buf[k];
>       k += strlen(value) + 1;
>
>       if (strcasecmp(key, "tsize") == 0) {
> diff --git a/slirp/tftp.h b/slirp/tftp.h
> index b9f0847..72e5e91 100644
> --- a/slirp/tftp.h
> +++ b/slirp/tftp.h
> @@ -26,7 +26,7 @@ struct tftp_t {
>       uint16_t tp_error_code;
>       uint8_t tp_msg[512];
>     } tp_error;
> -    uint8_t tp_buf[512 + 2];
> +    char tp_buf[512 + 2];
>   } x;
>  };
>
> --
> 1.7.2.3
>
>
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-02-25 18:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-23 18:40 [Qemu-devel] [PATCH] slirp: Remove some type casts caused by bad declaration of x.tp_buf Stefan Weil
2011-02-25 18:07 ` Blue Swirl

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.