← Back to team overview

kicad-developers team mailing list archive

Re: [PATCH] Fix off-by-one in saving bitmaps

 

Le 08/11/2016 à 19:14, Jean-Noel Avila a écrit :
> As per the PNG format specification, the picture file ends with a IEND
> chunk which is constant with the following sequence:
> 
>  00 00 00 00 49 45 4E 44 AE 42 60 82
> |   length  |  "IEND"   |    CRC    |
> 
> Any byte beyond this sequence is not part of PNG.
> 
> When saving bitmaps as PNG, the stream was read one byte more than its
> actual width. This resulted in having the last byte of the serialized
> stream changing even when the bitmap isn't modified.
> 
> Signed-off-by: Jean-Noel Avila <jn.avila@xxxxxxx>
> ---
>  common/class_bitmap_base.cpp | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/common/class_bitmap_base.cpp b/common/class_bitmap_base.cpp
> index c563f1fc4..bd5159935 100644
> --- a/common/class_bitmap_base.cpp
> +++ b/common/class_bitmap_base.cpp
> @@ -109,7 +109,7 @@ bool BITMAP_BASE::SaveData( FILE* aFile ) const
>          char*           begin  = (char*) buffer->GetBufferStart();
>          int             ii;
>  
> -        for( ii = 0; begin <= buffer->GetBufferEnd(); begin++, ii++ )
> +        for( ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
>          {
>              if( ii >= 32 )
>              {
> @@ -140,7 +140,7 @@ void BITMAP_BASE::SaveData( wxArrayString& aPngStrings ) const
>          char*           begin  = (char*) buffer->GetBufferStart();
>          wxString        line;
>  
> -        for( int ii = 0; begin <= buffer->GetBufferEnd(); begin++, ii++ )
> +        for( int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
>          {
>              if( ii >= 32 )
>              {
> 


Thanks, Jean-Noel.
I committed your fix both to the master and stable branches.

-- 
Jean-Pierre CHARRAS


References