Skip to content

Commit 27e548a

Browse files
committed
chore: Clean up the return statements and update example.c accordingly
1 parent 92b2128 commit 27e548a

File tree

11 files changed

+159
-159
lines changed

11 files changed

+159
-159
lines changed

example.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
/* example.c - an example of using libpng
55
*
6-
* Maintained 2018 Cosmin Truta
6+
* Maintained 2018-2024 Cosmin Truta
77
* Maintained 1998-2016 Glenn Randers-Pehrson
88
* Maintained 1996-1997 Andreas Dilger
99
* Written 1995-1996 Guy Eric Schalnat, Group 42, Inc.
@@ -259,9 +259,9 @@ int check_if_png(char *file_name, FILE **fp)
259259
return 0;
260260

261261
/* Compare the first PNG_BYTES_TO_CHECK bytes of the signature.
262-
* Return nonzero (true) if they match.
262+
* Return true if they match.
263263
*/
264-
return(!png_sig_cmp(buf, 0, PNG_BYTES_TO_CHECK));
264+
return png_sig_cmp(buf, 0, PNG_BYTES_TO_CHECK) == 0;
265265
}
266266

267267
/* Read a PNG file. You may want to return an error code if the read
@@ -281,7 +281,7 @@ void read_png(char *file_name) /* We need to open the file */
281281
FILE *fp;
282282

283283
if ((fp = fopen(file_name, "rb")) == NULL)
284-
return (ERROR);
284+
return ERROR;
285285

286286
#else no_open_file /* prototype 2 */
287287
void read_png(FILE *fp, int sig_read) /* File is already open */
@@ -304,7 +304,7 @@ void read_png(FILE *fp, int sig_read) /* File is already open */
304304
if (png_ptr == NULL)
305305
{
306306
fclose(fp);
307-
return (ERROR);
307+
return ERROR;
308308
}
309309

310310
/* Allocate/initialize the memory for image information. REQUIRED. */
@@ -313,7 +313,7 @@ void read_png(FILE *fp, int sig_read) /* File is already open */
313313
{
314314
fclose(fp);
315315
png_destroy_read_struct(&png_ptr, NULL, NULL);
316-
return (ERROR);
316+
return ERROR;
317317
}
318318

319319
/* Set error handling if you are using the setjmp/longjmp method (this is
@@ -326,7 +326,7 @@ void read_png(FILE *fp, int sig_read) /* File is already open */
326326
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
327327
fclose(fp);
328328
/* If we get here, we had a problem reading the file. */
329-
return (ERROR);
329+
return ERROR;
330330
}
331331

332332
/* One of the following I/O initialization methods is REQUIRED. */
@@ -585,7 +585,7 @@ void read_png(FILE *fp, int sig_read) /* File is already open */
585585
fclose(fp);
586586

587587
/* That's it! */
588-
return (OK);
588+
return OK;
589589
}
590590

591591
/* Progressively read a file */
@@ -604,18 +604,18 @@ initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr)
604604
if (*png_ptr == NULL)
605605
{
606606
*info_ptr = NULL;
607-
return (ERROR);
607+
return ERROR;
608608
}
609609
*info_ptr = png_create_info_struct(png_ptr);
610610
if (*info_ptr == NULL)
611611
{
612612
png_destroy_read_struct(png_ptr, info_ptr, NULL);
613-
return (ERROR);
613+
return ERROR;
614614
}
615615
if (setjmp(png_jmpbuf((*png_ptr))))
616616
{
617617
png_destroy_read_struct(png_ptr, info_ptr, NULL);
618-
return (ERROR);
618+
return ERROR;
619619
}
620620

621621
/* You will need to provide all three function callbacks,
@@ -632,7 +632,7 @@ initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr)
632632
*/
633633
png_set_progressive_read_fn(*png_ptr, (void *)stream_data,
634634
info_callback, row_callback, end_callback);
635-
return (OK);
635+
return OK;
636636
}
637637

638638
int
@@ -643,7 +643,7 @@ process_data(png_structp *png_ptr, png_infop *info_ptr,
643643
{
644644
/* Free the png_ptr and info_ptr memory on error. */
645645
png_destroy_read_struct(png_ptr, info_ptr, NULL);
646-
return (ERROR);
646+
return ERROR;
647647
}
648648

649649
/* Give chunks of data as they arrive from the data stream
@@ -657,7 +657,7 @@ process_data(png_structp *png_ptr, png_infop *info_ptr,
657657
* callback, if you aren't already displaying them there.
658658
*/
659659
png_process_data(*png_ptr, *info_ptr, buffer, length);
660-
return (OK);
660+
return OK;
661661
}
662662

663663
info_callback(png_structp png_ptr, png_infop info)
@@ -747,7 +747,7 @@ void write_png(char *file_name /* , ... other image information ... */)
747747
/* Open the file */
748748
fp = fopen(file_name, "wb");
749749
if (fp == NULL)
750-
return (ERROR);
750+
return ERROR;
751751

752752
/* Create and initialize the png_struct with the desired error handler
753753
* functions. If you want to use the default stderr and longjump method,
@@ -760,7 +760,7 @@ void write_png(char *file_name /* , ... other image information ... */)
760760
if (png_ptr == NULL)
761761
{
762762
fclose(fp);
763-
return (ERROR);
763+
return ERROR;
764764
}
765765

766766
/* Allocate/initialize the image information data. REQUIRED. */
@@ -769,7 +769,7 @@ void write_png(char *file_name /* , ... other image information ... */)
769769
{
770770
fclose(fp);
771771
png_destroy_write_struct(&png_ptr, NULL);
772-
return (ERROR);
772+
return ERROR;
773773
}
774774

775775
/* Set up error handling. REQUIRED if you aren't supplying your own
@@ -780,7 +780,7 @@ void write_png(char *file_name /* , ... other image information ... */)
780780
/* If we get here, we had a problem writing the file. */
781781
fclose(fp);
782782
png_destroy_write_struct(&png_ptr, &info_ptr);
783-
return (ERROR);
783+
return ERROR;
784784
}
785785

786786
/* One of the following I/O initialization functions is REQUIRED. */
@@ -1035,7 +1035,7 @@ void write_png(char *file_name /* , ... other image information ... */)
10351035
fclose(fp);
10361036

10371037
/* That's it! */
1038-
return (OK);
1038+
return OK;
10391039
}
10401040

10411041
#endif /* if 0 */

png.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ png_sig_cmp(png_const_bytep sig, size_t start, size_t num_to_check)
5959
num_to_check = 8;
6060

6161
else if (num_to_check < 1)
62-
return (-1);
62+
return -1;
6363

6464
if (start > 7)
65-
return (-1);
65+
return -1;
6666

6767
if (start + num_to_check > 8)
6868
num_to_check = 8 - start;
6969

70-
return ((int)(memcmp(&sig[start], &png_signature[start], num_to_check)));
70+
return memcmp(&sig[start], &png_signature[start], num_to_check);
7171
}
7272

7373
#endif /* READ */
@@ -665,9 +665,9 @@ png_voidp PNGAPI
665665
png_get_io_ptr(png_const_structrp png_ptr)
666666
{
667667
if (png_ptr == NULL)
668-
return (NULL);
668+
return NULL;
669669

670-
return (png_ptr->io_ptr);
670+
return png_ptr->io_ptr;
671671
}
672672

673673
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
@@ -956,7 +956,7 @@ png_reset_zstream(png_structrp png_ptr)
956956
return Z_STREAM_ERROR;
957957

958958
/* WARNING: this resets the window bits to the maximum! */
959-
return (inflateReset(&png_ptr->zstream));
959+
return inflateReset(&png_ptr->zstream);
960960
}
961961
#endif /* READ */
962962

@@ -965,7 +965,7 @@ png_uint_32 PNGAPI
965965
png_access_version_number(void)
966966
{
967967
/* Version of *.c files used when building libpng */
968-
return((png_uint_32)PNG_LIBPNG_VER);
968+
return (png_uint_32)PNG_LIBPNG_VER;
969969
}
970970

971971
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)

png.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -908,15 +908,15 @@ PNG_EXPORT(2, void, png_set_sig_bytes, (png_structrp png_ptr, int num_bytes));
908908
/* Check sig[start] through sig[start + num_to_check - 1] to see if it's a
909909
* PNG file. Returns zero if the supplied bytes match the 8-byte PNG
910910
* signature, and non-zero otherwise. Having num_to_check == 0 or
911-
* start > 7 will always fail (ie return non-zero).
911+
* start > 7 will always fail (i.e. return non-zero).
912912
*/
913913
PNG_EXPORT(3, int, png_sig_cmp, (png_const_bytep sig, size_t start,
914914
size_t num_to_check));
915915

916916
/* Simple signature checking function. This is the same as calling
917-
* png_check_sig(sig, n) := !png_sig_cmp(sig, 0, n).
917+
* png_check_sig(sig, n) := (png_sig_cmp(sig, 0, n) != 0).
918918
*/
919-
#define png_check_sig(sig, n) !png_sig_cmp((sig), 0, (n))
919+
#define png_check_sig(sig, n) (png_sig_cmp((sig), 0, (n)) != 0)
920920

921921
/* Allocate and initialize png_ptr struct for reading, and any other memory. */
922922
PNG_EXPORTA(4, png_structp, png_create_read_struct,

pngerror.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
/* pngerror.c - stub functions for i/o and memory allocation
33
*
4-
* Copyright (c) 2018 Cosmin Truta
4+
* Copyright (c) 2018-2024 Cosmin Truta
55
* Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson
66
* Copyright (c) 1996-1997 Andreas Dilger
77
* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
@@ -858,7 +858,7 @@ png_get_error_ptr(png_const_structrp png_ptr)
858858
if (png_ptr == NULL)
859859
return NULL;
860860

861-
return ((png_voidp)png_ptr->error_ptr);
861+
return (png_voidp)png_ptr->error_ptr;
862862
}
863863

864864

0 commit comments

Comments
 (0)