libmicrohttpd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libmicrohttpd] please correct type of "max" in MHD_ContentReaderCal


From: Christian Grothoff
Subject: Re: [libmicrohttpd] please correct type of "max" in MHD_ContentReaderCallback
Date: Tue, 21 Sep 2010 15:14:54 +0200
User-agent: KMail/1.13.5 (Linux/2.6.32-trunk-vserver-amd64; KDE/4.4.5; x86_64; ; )

I've changed this as suggested in SVN HEAD.  Note that this will now cause 
(harmless) compiler warnings for software written using the old API.

Happy hacking,

Christian

On Tuesday 21 September 2010 11:37:05 Jim Meyering wrote:
> Hello,
> 
> First, thank you for writing/maintaining libmicrohttpd.
> 
> I noticed that when I used what I thought was the right type for "max",
> I'd get this sort of warning:
> 
>     rest.c:962: warning: passing argument 3 of
> 'MHD_create_response_from_callback' from incompatible pointer type
> /usr/include/microhttpd.h:1085: note: expected 'MHD_ContentReaderCallback'
> but argument is of type 'int (*)(void *, uint64_t,  char *, size_t)'
> 
> The current interface would require that I use "int",
> but it's a buffer size limit, and hence should have type size_t.
> Please use size_t instead.
> 
> A public interface like microhttpd.h should not encourage/force
> client applications to use a signed type ("int") for a buffer size.
> Here's a proposed patch:
> 
> Index: src/include/microhttpd.h
> ===================================================================
> --- src/include/microhttpd.h  (revision 13036)
> +++ src/include/microhttpd.h  (working copy)
> @@ -880,7 +880,7 @@
>    (*MHD_ContentReaderCallback) (void *cls,
>                               uint64_t pos,
>                               char *buf,
> -                             int max);
> +                             size_t max);
> 
>  /**
>   * This method is called by libmicrohttpd if we
> 
> Otherwise, with the existing definition,
> applications must choose between using the wrong type ("int")
> for that parameter, and using the proper type ("size_t") but
> dealing with type-mismatch warnings/errors.
> Adding casts is risky, and so is simply turning off the warnings.
> 
> Finally, I glanced through the sources and found minor problems
> in the test*/ directories.  It'd be nice to correct tests like this:
> 
>     url = malloc (VERY_LONG);
>     memset (url, 'a', VERY_LONG);
> 
> so that they do not dereference NULL upon OOM.
> This is from src/testcurl/daemontest_long_header.c, but there are others.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]