[PATCH] xts5: Realloc the reply buffer instead of failing

Aaron Plattner aplattner at nvidia.com
Wed Apr 25 00:46:20 PDT 2012


On 04/18/2012 03:23 PM, Aaron Plattner wrote:
> The default window size for test windows is Screen_Width/2 x Screen_Height/2.
> When the screen is really big, this can result in a very large window, which
> makes for a very large reply in the pGetImage tests.  If this reply is larger
> than max_extra, the test fails.  This failure is bogus -- at the very least, it
> should be UNRESOLVED instead.
>
> Instead of failing in this case, just make rbuf be dynamically-allocated and
> realloc it bigger as necessary.  Fixes Xproto/GetImage-1 when the root window is
> very large.
>
> Signed-off-by: Aaron Plattner <aplattner at nvidia.com>
> ---
>   xts5/src/libproto/Expect.c |   28 +++++++++++++++++++++-------
>   1 files changed, 21 insertions(+), 7 deletions(-)
>
> diff --git a/xts5/src/libproto/Expect.c b/xts5/src/libproto/Expect.c
> index cd93411..bdd6142 100644
> --- a/xts5/src/libproto/Expect.c
> +++ b/xts5/src/libproto/Expect.c
> @@ -138,8 +138,8 @@ SOFTWARE.
>   	int *countp = (Get_Test_Type(cl)==SETUP)?(&Xst_delete_count):(&Xst_error_count);\
>   	if (*countp>0) (*countp)--; } while (0)
>
> -static int  max_extra = IBUFSIZE - sizeof (xReply);
> -static char rbuf[IBUFSIZE];
> +static char *rbuf;
> +static size_t rbuf_size;
>   static char *rbp;
>   static char *enames ();
>   static char wanted[132];
> @@ -327,6 +327,15 @@ int     type;     /* request type */
>   	Poll_Server (client);
>       }
>
> +    if (!rbuf) {
> +	rbuf_size = IBUFSIZE;
> +	rbuf = Xstmalloc (rbuf_size);
> +	if (!rbuf) {
> +	    Log_Msg ("Could not allocate %d bytes to store reply data\n", rbuf_size);
> +	    Finish (client);
> +	}
> +    }
> +
>   /*
>    *	Now cycle through the messages coming back until we get something
>    *	which corresponds explicitly to the last request sent
> @@ -404,12 +413,17 @@ int     type;     /* request type */
>   	    case X_Reply:
>   		extra = (rep -> generic.length <<  2);
>   		if (extra>  0) {/* more to read */
> -		    if (extra>  max_extra) {
> -			Log_Msg ("Expect: too big a reply");
> -			Show_Rep (rep, UNKNOWN_REQUEST_TYPE, so_far);
> -			Finish  (client);
> -		    }
>   		    so_far = (long) extra + sizeof (xReply);
> +		    if (so_far > rbuf_size) {
> +			fprintf(stderr, "Reallocing rbuf from %d to %d\n", rbuf_size, so_far);

Whoops, pretend this debugging fprintf isn't there.

-- Aaron

> +			rbuf_size = so_far;
> +			rbuf = Xstrealloc (rbuf, so_far);
> +			if (!rbuf) {
> +			    Log_Msg ("Could not allocate %d bytes to store reply data\n",
> +				     rbuf_size);
> +			    Finish (client);
> +			}
> +		    }
>   		    rep = (xReply *) Xstrealloc ((char *) rep, (unsigned) so_far);
>   		    Get_Me_That (client, (char *) rbuf + sizeof (xReply), extra);
>   		}



More information about the xorg-test mailing list