Closed zvezdochiot closed 2 years ago
From these functions, I can return the number of bytes (not bits) that will need to be allocated with malloc.
I should also check whether malloc succeeded.
@nkkav say:
From these functions, I can return the number of bytes (not bits) that will need to be allocated with malloc.
I'm not sure my point is understood.
https://github.com/nkkav/libpnmio/blob/fcb31cf3eadc5b48ec9cf867c2dc3c32ed2717b1/src/rnwimg.c#L128 https://github.com/nkkav/libpnmio/blob/fcb31cf3eadc5b48ec9cf867c2dc3c32ed2717b1/src/rnwimg.c#L159
to
read_ppm_header(imgin_file, &x_dim, &y_dim, &img_colors, &enable_ascii, &bit_size);
img_data = malloc(bit_size);
your point is understood. You prefer to not return but to update the pass-by-reference argument.
malloc takes number of bytes as input, not bits. sizeof()
returns bytes, not bits. malloc()
allocates bytes in a byte-addressable memory model, not bits. There is no bit concept in C except "bit-fields" (where the concept is defined very specifically and is not really about storage bits and the necessary value of CHAR_BIT
. Bit-accurate types in the strong sense are only under discussion for C23.
@nkkav say:
malloc takes number of bytes as input, not bits.
The name doesn't matter. You know better. My English is bad. (https://translate.google.ru/)
Finally done. Thank you
https://github.com/nkkav/libpnmio/blob/fcb31cf3eadc5b48ec9cf867c2dc3c32ed2717b1/src/pnmio.h#L53-L59
https://github.com/nkkav/libpnmio/blob/fcb31cf3eadc5b48ec9cf867c2dc3c32ed2717b1/src/rnwimg.c#L123-L132
https://github.com/nkkav/libpnmio/blob/fcb31cf3eadc5b48ec9cf867c2dc3c32ed2717b1/src/rnwimg.c#L154-L162
I think this construction is incorrect,
read_ {pbm, pgm, ppm, pfm} _header
should also return thebitsize
parameter, which should already be used formalloc
.