[1/2] rangecoder: Drop incorrect const from ff_init_range_decoder

Message ID 1480539757-6450-1-git-send-email-diego@biurrun.de
State New
Headers show

Commit Message

Diego Biurrun Nov. 30, 2016, 9:02 p.m.
libavcodec/rangecoder.c:57:30: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]
---
 libavcodec/rangecoder.c | 6 ++----
 libavcodec/rangecoder.h | 2 +-
 2 files changed, 3 insertions(+), 5 deletions(-)

Comments

Anton Khirnov Nov. 30, 2016, 9:08 p.m. | #1
Quoting Diego Biurrun (2016-11-30 22:02:36)
> libavcodec/rangecoder.c:57:30: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]
> ---
>  libavcodec/rangecoder.c | 6 ++----
>  libavcodec/rangecoder.h | 2 +-
>  2 files changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/libavcodec/rangecoder.c b/libavcodec/rangecoder.c
> index 4c4731d..3ef4b31 100644
> --- a/libavcodec/rangecoder.c
> +++ b/libavcodec/rangecoder.c
> @@ -49,11 +49,9 @@ av_cold void ff_init_range_encoder(RangeCoder *c, uint8_t *buf, int buf_size)
>      c->outstanding_byte  = -1;
>  }
>  
> -av_cold void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf,
> -                                   int buf_size)
> +av_cold void ff_init_range_decoder(RangeCoder *c, uint8_t *buf, int buf_size)
>  {
> -    /* cast to avoid compiler warning */
> -    ff_init_range_encoder(c, (uint8_t *)buf, buf_size);
> +    ff_init_range_encoder(c, buf, buf_size);
>  
>      c->low         = AV_RB16(c->bytestream);
>      c->bytestream += 2;
> diff --git a/libavcodec/rangecoder.h b/libavcodec/rangecoder.h
> index 2ead446..c07a99b 100644
> --- a/libavcodec/rangecoder.h
> +++ b/libavcodec/rangecoder.h
> @@ -45,7 +45,7 @@ typedef struct RangeCoder {
>  } RangeCoder;
>  
>  void ff_init_range_encoder(RangeCoder *c, uint8_t *buf, int buf_size);
> -void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, int buf_size);
> +void ff_init_range_decoder(RangeCoder *c, uint8_t *buf, int buf_size);
>  int ff_rac_terminate(RangeCoder *c);
>  void ff_build_rac_states(RangeCoder *c, int factor, int max_p);
>  
> -- 
> 2.1.4

Why is it incorrect? Does the range decoder modify the input buffer?

And I asked you multiple times already to stop just citing warnings as
justifications for such patches. A warning may or may not be a symptom
of a problem in the code. What you should be fixed is that underlying
problem, not the warning itself. And the commit message should properly
explain what the problem was and why the commit is the right way to
solve it.
Luca Barbato Nov. 30, 2016, 11:31 p.m. | #2
On 30/11/2016 22:02, Diego Biurrun wrote:
> libavcodec/rangecoder.c:57:30: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual]
> ---
>  libavcodec/rangecoder.c | 6 ++----
>  libavcodec/rangecoder.h | 2 +-
>  2 files changed, 3 insertions(+), 5 deletions(-)
> 

The const is correct, assuming you would like to avoid the warning you'd
have to have a separate ReadContext.

lu

Patch

diff --git a/libavcodec/rangecoder.c b/libavcodec/rangecoder.c
index 4c4731d..3ef4b31 100644
--- a/libavcodec/rangecoder.c
+++ b/libavcodec/rangecoder.c
@@ -49,11 +49,9 @@  av_cold void ff_init_range_encoder(RangeCoder *c, uint8_t *buf, int buf_size)
     c->outstanding_byte  = -1;
 }
 
-av_cold void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf,
-                                   int buf_size)
+av_cold void ff_init_range_decoder(RangeCoder *c, uint8_t *buf, int buf_size)
 {
-    /* cast to avoid compiler warning */
-    ff_init_range_encoder(c, (uint8_t *)buf, buf_size);
+    ff_init_range_encoder(c, buf, buf_size);
 
     c->low         = AV_RB16(c->bytestream);
     c->bytestream += 2;
diff --git a/libavcodec/rangecoder.h b/libavcodec/rangecoder.h
index 2ead446..c07a99b 100644
--- a/libavcodec/rangecoder.h
+++ b/libavcodec/rangecoder.h
@@ -45,7 +45,7 @@  typedef struct RangeCoder {
 } RangeCoder;
 
 void ff_init_range_encoder(RangeCoder *c, uint8_t *buf, int buf_size);
-void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, int buf_size);
+void ff_init_range_decoder(RangeCoder *c, uint8_t *buf, int buf_size);
 int ff_rac_terminate(RangeCoder *c);
 void ff_build_rac_states(RangeCoder *c, int factor, int max_p);