[PATCH: libXdmcp 4/4] Deal with lint warnings about implicit narrowing conversions

Matt Turner mattst88 at gmail.com
Wed May 5 13:06:00 PDT 2010


On Wed, May 5, 2010 at 3:47 PM, Alan Coopersmith
<alan.coopersmith at oracle.com> wrote:
> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
> ---
>
> It's tempting to just change the struct definitions to use int instead of
> CARD8 or CARD16 for length, but that's part of the ABI used by callers
> such as libX11 and the X server, and it's not worth the hassle of bumping
> SONAME to libXdmcp.so.7 just for that.
>
>  AA16.c   |    7 ++++++-
>  AA32.c   |    7 ++++++-
>  AA8.c    |    7 ++++++-
>  AofA8.c  |    7 ++++++-
>  RAofA8.c |    4 ++--
>  RaA16.c  |    6 +++++-
>  RaA32.c  |    7 ++++++-
>  RaA8.c   |    7 ++++++-
>  RaAoA8.c |    7 ++++++-
>  9 files changed, 49 insertions(+), 10 deletions(-)
>
> diff --git a/AA16.c b/AA16.c
> index 5de5caf..049a24a 100644
> --- a/AA16.c
> +++ b/AA16.c
> @@ -36,16 +36,21 @@ in this Software without prior written authorization from The Open Group.
>  #include <X11/X.h>
>  #include <X11/Xmd.h>
>  #include <X11/Xdmcp.h>
> +#include <limits.h>
>
>  int
>  XdmcpAllocARRAY16 (ARRAY16Ptr array, int length)
>  {
>     CARD16Ptr  newData;
>
> +    /* length defined in ARRAY16 struct is a CARD8 */
> +    if (length > UINT8_MAX)
> +       return FALSE;
> +
>     newData = (CARD16Ptr) Xalloc (length * sizeof (CARD16));
>     if (!newData)
>        return FALSE;
> -    array->length = length;
> +    array->length = (CARD8) length;
>     array->data = newData;
>     return TRUE;
>  }
> diff --git a/AA32.c b/AA32.c
> index fbeded1..5687a9a 100644
> --- a/AA32.c
> +++ b/AA32.c
> @@ -36,16 +36,21 @@ in this Software without prior written authorization from The Open Group.
>  #include <X11/X.h>
>  #include <X11/Xmd.h>
>  #include <X11/Xdmcp.h>
> +#include <limits.h>
>
>  int
>  XdmcpAllocARRAY32 (ARRAY32Ptr array, int length)
>  {
>     CARD32Ptr  newData;
>
> +    /* length defined in ARRAY32 struct is a CARD8 */
> +    if (length > UINT8_MAX)
> +       return FALSE;
> +
>     newData = (CARD32Ptr) Xalloc (length * sizeof (CARD32));
>     if (!newData)
>        return FALSE;
> -    array->length = length;
> +    array->length = (CARD8) length;
>     array->data = newData;
>     return TRUE;
>  }
> diff --git a/AA8.c b/AA8.c
> index 391e788..1cb29d4 100644
> --- a/AA8.c
> +++ b/AA8.c
> @@ -36,16 +36,21 @@ in this Software without prior written authorization from The Open Group.
>  #include <X11/X.h>
>  #include <X11/Xmd.h>
>  #include <X11/Xdmcp.h>
> +#include <limits.h>
>
>  int
>  XdmcpAllocARRAY8 (ARRAY8Ptr array, int length)
>  {
>     CARD8Ptr   newData;
>
> +    /* length defined in ARRAY8 struct is a CARD16 (not CARD8 like the rest) */
> +    if (length > UINT16_MAX)
> +       return FALSE;
> +
>     newData = (CARD8Ptr) Xalloc (length * sizeof (CARD8));
>     if (!newData)
>        return FALSE;
> -    array->length = length;
> +    array->length = (CARD16) length;
>     array->data = newData;
>     return TRUE;
>  }
> diff --git a/AofA8.c b/AofA8.c
> index fe77330..93cf4e6 100644
> --- a/AofA8.c
> +++ b/AofA8.c
> @@ -36,16 +36,21 @@ in this Software without prior written authorization from The Open Group.
>  #include <X11/X.h>
>  #include <X11/Xmd.h>
>  #include <X11/Xdmcp.h>
> +#include <limits.h>
>
>  int
>  XdmcpAllocARRAYofARRAY8 (ARRAYofARRAY8Ptr array, int length)
>  {
>     ARRAY8Ptr  newData;
>
> +    /* length defined in ARRAYofARRAY8 struct is a CARD8 */
> +    if (length > UINT8_MAX)
> +       return FALSE;
> +
>     newData = (ARRAY8Ptr) Xalloc (length * sizeof (ARRAY8));
>     if (!newData)
>        return FALSE;
> -    array->length = length;
> +    array->length = (CARD8) length;
>     array->data = newData;
>     return TRUE;
>  }
> diff --git a/RAofA8.c b/RAofA8.c
> index 7c8563f..2df3c24 100644
> --- a/RAofA8.c
> +++ b/RAofA8.c
> @@ -38,7 +38,7 @@ in this Software without prior written authorization from The Open Group.
>  int
>  XdmcpReadARRAYofARRAY8 (XdmcpBufferPtr buffer, ARRAYofARRAY8Ptr array)
>  {
> -    int            i;
> +    CARD8    i;
>
>     if (!XdmcpReadCARD8 (buffer, &array->length)) {
>
> @@ -56,7 +56,7 @@ XdmcpReadARRAYofARRAY8 (XdmcpBufferPtr buffer, ARRAYofARRAY8Ptr array)
>     array->data = (ARRAY8 *) Xalloc (array->length * sizeof (ARRAY8));
>     if (!array->data)
>        return FALSE;
> -    for (i = 0; i < (int)array->length; i++)
> +    for (i = 0; i < array->length; i++)
>     {
>        if (!XdmcpReadARRAY8 (buffer, &array->data[i]))
>        {
> diff --git a/RaA16.c b/RaA16.c
> index b02fa2f..96f87b5 100644
> --- a/RaA16.c
> +++ b/RaA16.c
> @@ -36,16 +36,20 @@ in this Software without prior written authorization from The Open Group.
>  #include <X11/X.h>
>  #include <X11/Xmd.h>
>  #include <X11/Xdmcp.h>
> +#include <limits.h>
>
>  int
>  XdmcpReallocARRAY16 (ARRAY16Ptr array, int length)
>  {
>     CARD16Ptr  newData;
>
> +    /* length defined in ARRAY16 struct is a CARD8 */
> +    if (length > UINT8_MAX)
> +       return FALSE;
>     newData = (CARD16Ptr) Xrealloc (array->data, length * sizeof (CARD16));
>     if (!newData)
>        return FALSE;
> -    array->length = length;
> +    array->length = (CARD8) length;
>     array->data = newData;
>     return TRUE;
>  }
> diff --git a/RaA32.c b/RaA32.c
> index 52167d1..93037e3 100644
> --- a/RaA32.c
> +++ b/RaA32.c
> @@ -36,16 +36,21 @@ in this Software without prior written authorization from The Open Group.
>  #include <X11/X.h>
>  #include <X11/Xmd.h>
>  #include <X11/Xdmcp.h>
> +#include <limits.h>
>
>  int
>  XdmcpReallocARRAY32 (ARRAY32Ptr array, int length)
>  {
>     CARD32Ptr  newData;
>
> +    /* length defined in ARRAY32 struct is a CARD8 */
> +    if (length > UINT8_MAX)
> +       return FALSE;
> +
>     newData = (CARD32Ptr) Xrealloc (array->data, length * sizeof (CARD32));
>     if (!newData)
>        return FALSE;
> -    array->length = length;
> +    array->length = (CARD8) length;
>     array->data = newData;
>     return TRUE;
>  }
> diff --git a/RaA8.c b/RaA8.c
> index 3e7bc08..ac85ae7 100644
> --- a/RaA8.c
> +++ b/RaA8.c
> @@ -36,16 +36,21 @@ in this Software without prior written authorization from The Open Group.
>  #include <X11/X.h>
>  #include <X11/Xmd.h>
>  #include <X11/Xdmcp.h>
> +#include <limits.h>
>
>  int
>  XdmcpReallocARRAY8 (ARRAY8Ptr array, int length)
>  {
>     CARD8Ptr   newData;
>
> +    /* length defined in ARRAY8 struct is a CARD16 (not CARD8 like the rest) */
> +    if (length > UINT16_MAX)
> +       return FALSE;
> +
>     newData = (CARD8Ptr) Xrealloc (array->data, length * sizeof (CARD8));
>     if (!newData)
>        return FALSE;
> -    array->length = length;
> +    array->length = (CARD16) length;
>     array->data = newData;
>     return TRUE;
>  }
> diff --git a/RaAoA8.c b/RaAoA8.c
> index 8b4806c..6ef5a09 100644
> --- a/RaAoA8.c
> +++ b/RaAoA8.c
> @@ -36,16 +36,21 @@ in this Software without prior written authorization from The Open Group.
>  #include <X11/X.h>
>  #include <X11/Xmd.h>
>  #include <X11/Xdmcp.h>
> +#include <limits.h>
>
>  int
>  XdmcpReallocARRAYofARRAY8 (ARRAYofARRAY8Ptr array, int length)
>  {
>     ARRAY8Ptr  newData;
>
> +    /* length defined in ARRAYofARRAY8 struct is a CARD8 */
> +    if (length > UINT8_MAX)
> +       return FALSE;
> +
>     newData = (ARRAY8Ptr) Xrealloc (array->data, length * sizeof (ARRAY8));
>     if (!newData)
>        return FALSE;
> -    array->length = length;
> +    array->length = (CARD8) length;
>     array->data = newData;
>     return TRUE;
>  }
> --
> 1.5.6.5
>
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
>

Reviewed-by: Matt Turner <mattst88 at gmail.com>


More information about the xorg-devel mailing list