[FFmpeg-devel] [PATCH] Make small_strptime() return char*

Stefano Sabatini stefano.sabatini-lala
Sun Jan 4 13:01:41 CET 2009


On date Saturday 2009-01-03 20:36:03 +0100, Stefano Sabatini encoded:
> Hi,
> 
> strptime() has as signature:
> char *strptime(const char *p, const char *fmt, struct tm *dt);
> 
> while we have:
> const char *small_strptime(const char *p, const char *fmt, struct tm*dt);
> 
> 
> Patch changes the constness of the returned signature to make it more
> similar to the standard one, this also fixes a warning in
> libavformat/utils.c:
> utils.c: In function ?parse_date?:
> utils.c:2948: warning: cast discards qualifiers from pointer target type
> 
> which occurrs in the code:
>             dt.tm_sec = strtol(p, (char **)&q, 10);
> 
> (q is a const char*, so we're passing to strtol a const char**).
> 
> The patch shoudn't break API / ABI, so a micro version bump should be sufficient.

Rethinking about it... the patches fix a warning but generate two
new warnings in cutils.c:
cutils.c:131: warning: return discards qualifiers from pointer target type
cutils.c:183: warning: cast discards qualifiers from pointer target type

They IMHO belong to the category of unavoidable warnings (and gcc
unfortunately lacks some way to disable them), but it is consistent
with the semantics of strptime:

char *small_strptime(const char *p, const char *fmt, struct tm *dt)

that is:
take in input a const char* (const pointer to a string which the
function has to *not* change) _but_ return a pointer to a string
which may *eventually* be modified.

Instead the idea of changing:

> Index: ffmpeg/libavformat/utils.c
> ===================================================================
> --- ffmpeg.orig/libavformat/utils.c	2009-01-03 20:33:28.000000000 +0100
> +++ ffmpeg/libavformat/utils.c	2009-01-03 20:33:53.000000000 +0100
> @@ -2884,7 +2884,7 @@
>          "%H:%M:%S",
>          "%H%M%S",
>      };
> -    const char *q;
> +    char *q;
>      int is_utc, len;
>      char lastch;
>      int negative = 0;

is just bad since it removes a useful semantic constraints on the q
var.

So I'm updating the patches, to simply make our small_strptime()
signature consistent with that of the standard strptime().

Sorry for the noise, regards.
-- 
FFmpeg = Forgiving Free Mysterious Power Elaborated Game
-------------- next part --------------
A non-text attachment was scrubbed...
Name: change-const-to-small-strptime.patch
Type: text/x-diff
Size: 1014 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090104/104fbe0d/attachment.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: reindent-small-strptime.patch
Type: text/x-diff
Size: 1102 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090104/104fbe0d/attachment-0001.patch>



More information about the ffmpeg-devel mailing list