[Top][All Lists]

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

[libmicrohttpd] please correct type of "max" in MHD_ContentReaderCallbac

From: Jim Meyering
Subject: [libmicrohttpd] please correct type of "max" in MHD_ContentReaderCallback
Date: Tue, 21 Sep 2010 11:37:05 +0200


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]