<html><head></head><body>Hi,<br><br>This warning has served me many times both to find bugs and to clean code up.<br><br>If it triggers here, maybe the API should be improved...<br><br><div class="gmail_quote">Le 17 avril 2020 09:02:25 GMT+03:00, Thomas Guillem <thomas@gllm.fr> a écrit :<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail"><br><br>On Fri, Apr 17, 2020, at 07:54, Steve Lhomme wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;">On 2020-04-16 20:58, Thomas Guillem wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ad7fa8; padding-left: 1ex;"><br>On Thu, Apr 16, 2020, at 16:05, Marvin Scholz wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #8ae234; padding-left: 1ex;"><hr>   include/vlc_hash.h    | 16 ++++++++--------<br>   include/vlc_strings.h |  5 +++--<br>   src/text/strings.c    |  6 ++++--<br>   3 files changed, 15 insertions(+), 12 deletions(-)<br><br> diff --git a/include/vlc_hash.h b/include/vlc_hash.h<br> index 1e7757ac58..b5136677d2 100644<br> --- a/include/vlc_hash.h<br> +++ b/include/vlc_hash.h<br> @@ -57,14 +57,14 @@<br>    * \param[out]    output Output buffer to write the string to<br>    */<br>   #ifndef __cplusplus<br> -#define vlc_hash_FinishHex(ctx, output, size)                       \<br> -    do {                                                            \<br> -        char out_tmp[_Generic((ctx),                                \<br> -            vlc_hash_md5_t *: VLC_HASH_MD5_DIGEST_SIZE)];           \<br> -        _Generic((ctx),                                             \<br> -            vlc_hash_md5_t *: vlc_hash_md5_Finish)                  \<br> -        (ctx, out_tmp, sizeof(out_tmp));                            \<br> -        vlc_hex_encode_binary(out_tmp, sizeof(out_tmp), output);    \<br> +#define vlc_hash_FinishHex(ctx, output, size)                           \<br> +    do {                                                                \<br> +        char out_tmp[_Generic((ctx),                                    \<br> +            vlc_hash_md5_t *: VLC_HASH_MD5_DIGEST_SIZE)];               \<br> +        _Generic((ctx),                                                 \<br> +            vlc_hash_md5_t *: vlc_hash_md5_Finish)                      \<br> +        (ctx, out_tmp, sizeof(out_tmp));                                \<br> +        vlc_hex_encode_binary(out_tmp, sizeof(out_tmp), output, size);  \<br>       } while (0)<br>   #endif<br>   <br> diff --git a/include/vlc_strings.h b/include/vlc_strings.h<br> index 930d3347fb..5b4436141f 100644<br> --- a/include/vlc_strings.h<br> +++ b/include/vlc_strings.h<br> @@ -125,10 +125,11 @@ VLC_API char *vlc_xml_encode(const char *str)<br> VLC_MALLOC;<br>    * string in hexadecimal representation.<br>    *<br>    * \param      input    Input buffer<br> - * \param      size     Input buffer size<br> + * \param      in_size  Input buffer size<br>    * \param[out] output   Output buffer to write the string to<br> + * \param      out_size Output buffer size<br>    */<br> -VLC_API void vlc_hex_encode_binary(const void *input, size_t size,<br> char *output);<br> +VLC_API void vlc_hex_encode_binary(const void *input, size_t in_size,<br> char *output, size_t out_size);<br>   <br>   /**<br>    * Base64 encoding.<br> diff --git a/src/text/strings.c b/src/text/strings.c<br> index 9676687aae..fc0babc7ce 100644<br> --- a/src/text/strings.c<br> +++ b/src/text/strings.c<br> @@ -347,11 +347,13 @@ char *vlc_xml_encode (const char *str)<br>   }<br>   <br>   /* Hex encoding */<br> -void vlc_hex_encode_binary(const void *input, size_t size, char *output)<br> +void vlc_hex_encode_binary(const void *input, size_t in_size,<br> +                           char *output, size_t out_size)<br>   {<br> +    assert(out_size >= in_size * 2 + 1); // 2 chars per byte + null<br></blockquote>Missing a (void) out_size; to clear warning on builds with NDEBUG.<br></blockquote>Can we just disable this warning ? We keep adding dummy code just to <br>silence this warning. I don't think there are cases where it's useful to <br>know we don't use a variable (apart when cleaning an API but then a grep <br>is still needed to verify all the calls anyway).<br></blockquote><br>Personally, this warning saved me more than one time. I would prefer to keep it.<br><br>> <br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ad7fa8; padding-left: 1ex;">Otherwise, LGTM for the set.<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #8ae234; padding-left: 1ex;">       const unsigned char *buffer = input;<br>   <br> -    for (size_t i = 0; i < size; i++) {<br> +    for (size_t i = 0; i < in_size; i++) {<br>           sprintf(&output[i * 2], "%02hhx", buffer[i]);<br>       }<br>   }<br> -- <br> 2.24.1 (Apple Git-126)<hr> vlc-devel mailing list<br> To unsubscribe or modify your subscription options:<br> <a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a><br></blockquote><hr>vlc-devel mailing list<br>To unsubscribe or modify your subscription options:<br><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a><br><br></blockquote><hr>vlc-devel mailing list<br>To unsubscribe or modify your subscription options:<br><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a><br></blockquote><hr>vlc-devel mailing list<br>To unsubscribe or modify your subscription options:<br><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a></pre></blockquote></div><br>-- <br>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.</body></html>