Skip to content

Commit

Permalink
using ptrdiff_t is recommended for pointer arithmetic in C
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristy committed Nov 10, 2024
1 parent c3bd263 commit 2794ae7
Show file tree
Hide file tree
Showing 67 changed files with 668 additions and 668 deletions.
6 changes: 3 additions & 3 deletions coders/bmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ static size_t EncodeImage(Image *image,const size_t bytes_per_line,
break;
*q++=(unsigned char) i;
*q++=(*p);
p+=i;
p+=(ptrdiff_t) i;
}
/*
End of line.
Expand Down Expand Up @@ -1179,7 +1179,7 @@ static Image *ReadBMPImage(const ImageInfo *image_info,ExceptionInfo *exception)
y=-1;
break;
}
p+=4;
p+=(ptrdiff_t) 4;
}
}
}
Expand Down Expand Up @@ -2264,7 +2264,7 @@ static MagickBooleanType WriteBMPImage(const ImageInfo *image_info,Image *image)
GetPixelBlue(p),31));
}
*((unsigned short *) q)=pixel;
q+=2;
q+=(ptrdiff_t) 2;
p++;
}
for (x=2L*(ssize_t) image->columns; x < (ssize_t) bytes_per_line; x++)
Expand Down
2 changes: 1 addition & 1 deletion coders/cip.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ static MagickBooleanType WriteCIPImage(const ImageInfo *image_info,Image *image)
(((size_t) (3*ClampToQuantum(GetPixelLuma(image,p+0))/QuantumRange) & 0x03) << 0));
(void) FormatLocaleString(buffer,MaxTextExtent,"%02x",byte);
(void) WriteBlobString(image,buffer);
p+=4;
p+=(ptrdiff_t) 4;
}
if ((image->columns % 4) != 0)
{
Expand Down
4 changes: 2 additions & 2 deletions coders/clipboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ static Image *ReadCLIPBOARDImage(const ImageInfo *image_info,
ThrowReaderException(CoderError,"UnableToReadImageData");
}
p=(unsigned char *) clip_data;
p+=BMP_HEADER_SIZE;
p+=(ptrdiff_t) BMP_HEADER_SIZE;
(void) memcpy(p,clip_mem,clip_size);
(void) GlobalUnlock(clip_mem);
(void) CloseClipboard();
Expand Down Expand Up @@ -356,7 +356,7 @@ static MagickBooleanType WriteCLIPBOARDImage(const ImageInfo *image_info,
ThrowWriterException(CoderError,"UnableToWriteImageData");
}
p=(unsigned char *) clip_data;
p+=BMP_HEADER_SIZE;
p+=(ptrdiff_t) BMP_HEADER_SIZE;
(void) memcpy(clip_mem,p,length-BMP_HEADER_SIZE);
(void) GlobalUnlock(clip_mem);
clip_data=RelinquishMagickMemory(clip_data);
Expand Down
6 changes: 3 additions & 3 deletions coders/dcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -3674,7 +3674,7 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
else
index=(unsigned short) (*p | (*(p+1) << 8));
redmap[i]=(int) index;
p+=2;
p+=(ptrdiff_t) 2;
}
break;
}
Expand Down Expand Up @@ -3706,7 +3706,7 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
else
index=(unsigned short) (*p | (*(p+1) << 8));
greenmap[i]=(int) index;
p+=2;
p+=(ptrdiff_t) 2;
}
break;
}
Expand Down Expand Up @@ -3738,7 +3738,7 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
else
index=(unsigned short) (*p | (*(p+1) << 8));
bluemap[i]=(int) index;
p+=2;
p+=(ptrdiff_t) 2;
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion coders/dib.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ static size_t EncodeImage(Image *image,const size_t bytes_per_line,
break;
*q++=(unsigned char) i;
*q++=(*p);
p+=i;
p+=(ptrdiff_t) i;
}
/*
End of line.
Expand Down
2 changes: 1 addition & 1 deletion coders/fits.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ static Image *ReadFITSImage(const ImageInfo *image_info,
p=value;
if (*p == '=')
{
p+=2;
p+=(ptrdiff_t) 2;
while (isspace((int) ((unsigned char) *p)) != 0)
p++;
}
Expand Down
2 changes: 1 addition & 1 deletion coders/fpx.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ static Image *ReadFPXImage(const ImageInfo *image_info,ExceptionInfo *exception)
if (image->matte != MagickFalse)
SetPixelAlpha(q,ScaleCharToQuantum(*a));
q++;
r+=red_component->columnStride;
r+=(ptrdiff_t) red_component->columnStride;
g+=green_component->columnStride;
b+=blue_component->columnStride;
a+=alpha_component->columnStride;
Expand Down
8 changes: 4 additions & 4 deletions coders/hdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ static Image *ReadHDRImage(const ImageInfo *image_info,ExceptionInfo *exception)
count=ReadBlob(image,(size_t) count*sizeof(*p),p);
if (count < 1)
break;
p+=count;
p+=(ptrdiff_t) count;
}
}
}
Expand Down Expand Up @@ -628,7 +628,7 @@ static size_t HDRWriteRunlengthPixels(Image *image,unsigned char *pixels)
previous_count=0;
while ((runlength < MinimumRunlength) && (q < image->columns))
{
q+=runlength;
q+=(ptrdiff_t) runlength;
previous_count=(ssize_t) runlength;
runlength=1;
while ((pixels[q] == pixels[q+runlength]) &&
Expand All @@ -653,15 +653,15 @@ static size_t HDRWriteRunlengthPixels(Image *image,unsigned char *pixels)
break;
if (WriteBlob(image,(size_t) count*sizeof(*pixel),&pixels[p]) < 1)
break;
p+=count;
p+=(ptrdiff_t) count;
}
if (runlength >= MinimumRunlength)
{
pixel[0]=(unsigned char) (128+runlength);
pixel[1]=pixels[q];
if (WriteBlob(image,2*sizeof(*pixel),pixel) < 1)
break;
p+=runlength;
p+=(ptrdiff_t) runlength;
}
}
return(p);
Expand Down
8 changes: 4 additions & 4 deletions coders/heic.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,15 +548,15 @@ static MagickBooleanType ReadHEICImageHandle(const ImageInfo *image_info,
for (x=0; x < (ssize_t) image->columns; x++)
{
unsigned short pixel = (((unsigned short) *(p+1) << 8) |
(*(p+0))) << shift; p+=2;
(*(p+0))) << shift; p+=(ptrdiff_t) 2;
SetPixelRed(q,ScaleShortToQuantum(pixel));
pixel=(((unsigned short) *(p+1) << 8) | (*(p+0))) << shift; p+=2;
pixel=(((unsigned short) *(p+1) << 8) | (*(p+0))) << shift; p+=(ptrdiff_t) 2;
SetPixelGreen(q,ScaleShortToQuantum(pixel));
pixel=(((unsigned short) *(p+1) << 8) | (*(p+0))) << shift; p+=2;
pixel=(((unsigned short) *(p+1) << 8) | (*(p+0))) << shift; p+=(ptrdiff_t) 2;
SetPixelBlue(q,ScaleShortToQuantum(pixel));
if (image->matte != MagickFalse)
{
pixel=(((unsigned short) *(p+1) << 8) | (*(p+0))) << shift; p+=2;
pixel=(((unsigned short) *(p+1) << 8) | (*(p+0))) << shift; p+=(ptrdiff_t) 2;
SetPixelAlpha(q,ScaleShortToQuantum(pixel));
}
q++;
Expand Down
2 changes: 1 addition & 1 deletion coders/jbig.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ static Image *ReadJBIGImage(const ImageInfo *image_info,
count;

status=jbg_dec_in(&jbig_info,p,length,&count);
p+=count;
p+=(ptrdiff_t) count;
length-=(ssize_t) count;
}
} while ((status == JBG_EAGAIN) || (status == JBG_EOK));
Expand Down
2 changes: 1 addition & 1 deletion coders/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ static void JSONFormatLocaleFile(FILE *file,const char *format,
if (((int) *p >= 0x00) && ((int) *p <= 0x1f))
{
(void) FormatLocaleString(q,7,"\\u%04X",(int) *p);
q+=6;
q+=(ptrdiff_t) 6;
break;
}
*q++=(*p);
Expand Down
12 changes: 6 additions & 6 deletions coders/meta.c
Original file line number Diff line number Diff line change
Expand Up @@ -1682,23 +1682,23 @@ static size_t GetIPTCStream(unsigned char **info,size_t length)
{
if (strncmp((const char *) p,"8BIM",4))
break;
p+=4;
p+=(ptrdiff_t) 4;
extent-=4;
marker=(unsigned int) (*p) << 8 | *(p+1);
p+=2;
p+=(ptrdiff_t) 2;
extent-=2;
c=*p++;
extent--;
c|=0x01;
if ((size_t) c >= extent)
break;
p+=c;
p+=(ptrdiff_t) c;
extent-=c;
if (extent < 4)
break;
tag_length=(((size_t) *p) << 24) | (((size_t) *(p+1)) << 16) |
(((size_t) *(p+2)) << 8) | ((size_t) *(p+3));
p+=4;
p+=(ptrdiff_t) 4;
extent-=4;
if (tag_length > extent)
break;
Expand All @@ -1709,7 +1709,7 @@ static size_t GetIPTCStream(unsigned char **info,size_t length)
}
if ((tag_length & 0x01) != 0)
tag_length++;
p+=tag_length;
p+=(ptrdiff_t) tag_length;
extent-=tag_length;
}
/*
Expand Down Expand Up @@ -1806,7 +1806,7 @@ static size_t GetIPTCStream(unsigned char **info,size_t length)
}
if (tag_length > (length+1))
break;
p+=tag_length;
p+=(ptrdiff_t) tag_length;
length-=tag_length;
if (length == 0)
break;
Expand Down
4 changes: 2 additions & 2 deletions coders/miff.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,14 @@ static void PushRunlengthPacket(Image *image,const unsigned char *pixels,
*index=ConstrainColormapIndex(image,(ssize_t) (((size_t) *p << 24) |
((size_t) *(p+1) << 16) | ((size_t) *(p+2) << 8) |
(size_t) *(p+3)));
p+=4;
p+=(ptrdiff_t) 4;
break;
}
case 16:
{
*index=ConstrainColormapIndex(image,(ssize_t) ((size_t) (*p << 8) |
(size_t) *(p+1)));
p+=2;
p+=(ptrdiff_t) 2;
break;
}
case 8:
Expand Down
6 changes: 3 additions & 3 deletions coders/pcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,9 @@ static void Upsample(const size_t width,const size_t height,
*q=(unsigned char) ((((size_t) *p)+((size_t) *r)+1) >> 1);
*(q+1)=(unsigned char) ((((size_t) *p)+((size_t) *(p+2))+
((size_t) *r)+((size_t) *(r+2))+2) >> 2);
q+=2;
p+=2;
r+=2;
q+=(ptrdiff_t) 2;
p+=(ptrdiff_t) 2;
r+=(ptrdiff_t) 2;
}
*q++=(unsigned char) ((((size_t) *p++)+((size_t) *r++)+1) >> 1);
*q++=(unsigned char) ((((size_t) *p++)+((size_t) *r++)+1) >> 1);
Expand Down
2 changes: 1 addition & 1 deletion coders/pcx.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ static Image *ReadPCXImage(const ImageInfo *image_info,ExceptionInfo *exception)
break;
}
}
r+=pcx_info.planes;
r+=(ptrdiff_t) pcx_info.planes;
}
}
else
Expand Down
6 changes: 3 additions & 3 deletions coders/pict.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ static unsigned char *DecodeImage(Image *blob,Image *image,
&number_pixels);
if ((q-pixels+number_pixels) <= *extent)
(void) memcpy(q,p,(size_t) number_pixels);
q+=number_pixels;
q+=(ptrdiff_t) number_pixels;
j+=(ssize_t) (length*bytes_per_pixel+1);
}
else
Expand All @@ -539,7 +539,7 @@ static unsigned char *DecodeImage(Image *blob,Image *image,
{
if ((q-pixels+number_pixels) <= *extent)
(void) memcpy(q,p,(size_t) number_pixels);
q+=number_pixels;
q+=(ptrdiff_t) number_pixels;
}
j+=(ssize_t) bytes_per_pixel+1;
}
Expand Down Expand Up @@ -1354,7 +1354,7 @@ static Image *ReadPICTImage(const ImageInfo *image_info,
if ((tile_image->storage_class == DirectClass) &&
(pixmap.bits_per_pixel != 16))
{
p+=(pixmap.component_count-1)*tile_image->columns;
p+=(ptrdiff_t) (pixmap.component_count-1)*tile_image->columns;
if (p < pixels)
break;
}
Expand Down
22 changes: 11 additions & 11 deletions coders/png.c
Original file line number Diff line number Diff line change
Expand Up @@ -1993,7 +1993,7 @@ static int read_user_chunk_callback(png_struct *ping, png_unknown_chunkp chunk)
if (s[0] == 'E' && s[1] == 'x' && s[2] == 'i' &&
s[3] == 'f' && s[4] == '\0' && s[5] == '\0')
{
s+=6;
s+=(ptrdiff_t) 6;
i=6;
SetStringInfoLength(profile,chunk->size);
p=GetStringInfoDatum(profile);
Expand Down Expand Up @@ -5482,7 +5482,7 @@ static Image *ReadOneMNGImage(MngInfo* mng_info, const ImageInfo *image_info,
" MNG height: %.20g",(double) mng_info->mng_height);
}

p+=8;
p+=(ptrdiff_t) 8;
mng_info->ticks_per_second=(size_t) mng_get_long(p);

if (mng_info->ticks_per_second == 0)
Expand All @@ -5496,7 +5496,7 @@ static Image *ReadOneMNGImage(MngInfo* mng_info, const ImageInfo *image_info,
simplicity=0;

/* Skip nominal layer count, frame count, and play time */
p+=16;
p+=(ptrdiff_t) 16;
simplicity=(size_t) mng_get_long(p);

mng_type=1; /* Full MNG */
Expand Down Expand Up @@ -5900,7 +5900,7 @@ static Image *ReadOneMNGImage(MngInfo* mng_info, const ImageInfo *image_info,
if (change_delay == 2)
default_frame_delay=frame_delay;

p+=4;
p+=(ptrdiff_t) 4;

if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
Expand All @@ -5921,7 +5921,7 @@ static Image *ReadOneMNGImage(MngInfo* mng_info, const ImageInfo *image_info,
if (change_timeout == 2)
default_frame_timeout=frame_timeout;

p+=4;
p+=(ptrdiff_t) 4;

if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
Expand All @@ -5931,7 +5931,7 @@ static Image *ReadOneMNGImage(MngInfo* mng_info, const ImageInfo *image_info,
if (change_clipping && ((p-chunk) < (ssize_t) (length-16)))
{
fb=mng_read_box(previous_fb,(char) p[0],&p[1]);
p+=16;
p+=(ptrdiff_t) 16;
previous_fb=fb;

if (logging != MagickFalse)
Expand Down Expand Up @@ -6026,7 +6026,7 @@ static Image *ReadOneMNGImage(MngInfo* mng_info, const ImageInfo *image_info,
{
first_object=(p[0] << 8) | p[1];
last_object=(p[2] << 8) | p[3];
p+=4;
p+=(ptrdiff_t) 4;

for (i=(int) first_object; i <= (int) last_object; i++)
{
Expand Down Expand Up @@ -6104,7 +6104,7 @@ static Image *ReadOneMNGImage(MngInfo* mng_info, const ImageInfo *image_info,
{
first_object=(p[0] << 8) | p[1];
last_object=(p[2] << 8) | p[3];
p+=4;
p+=(ptrdiff_t) 4;

for (i=(ssize_t) first_object; i <= (ssize_t) last_object; i++)
{
Expand Down Expand Up @@ -6981,7 +6981,7 @@ static Image *ReadOneMNGImage(MngInfo* mng_info, const ImageInfo *image_info,
1,exception);
if (q == (PixelPacket *) NULL)
break;
q+=(large_image->columns-image->columns);
q+=(ptrdiff_t) (large_image->columns-image->columns);

for (x=(ssize_t) image->columns-1; x >= 0; x--)
{
Expand Down Expand Up @@ -13145,7 +13145,7 @@ static MagickBooleanType WriteOneJNGImage(MngInfo *mng_info,
(((unsigned int) *(p + 1) & 0xff) << 16) +
(((unsigned int) *(p + 2) & 0xff) << 8) +
(((unsigned int) *(p + 3) & 0xff) ) ;
p+=4;
p+=(ptrdiff_t) 4;

if (*(p)==73 && *(p+1)==68 && *(p+2)==65 && *(p+3)==84) /* IDAT */
{
Expand All @@ -13163,7 +13163,7 @@ static MagickBooleanType WriteOneJNGImage(MngInfo *mng_info,
" Skipping %c%c%c%c chunk, length=%.20g.",
*(p),*(p+1),*(p+2),*(p+3),(double) len);
}
p+=(8+len);
p+=(ptrdiff_t) (8+len);
}
}
else if (length != 0)
Expand Down
Loading

0 comments on commit 2794ae7

Please sign in to comment.