dj(1): add a ton of assertions, fix if statement, fix io[i] mixups

This commit is contained in:
dtb 2024-07-03 14:22:23 -06:00
parent 064abb82a6
commit 1cf67af281
Signed by: trinity
GPG Key ID: 34C0543BBB6AF81B

View File

@ -16,6 +16,7 @@
* along with this program. If not, see https://www.gnu.org/licenses/. * along with this program. If not, see https://www.gnu.org/licenses/.
*/ */
#include <assert.h> /* assert(3) */
#include <errno.h> /* errno */ #include <errno.h> /* errno */
#include <fcntl.h> /* open(2) */ #include <fcntl.h> /* open(2) */
#include <stdio.h> /* fprintf(3), stderr */ #include <stdio.h> /* fprintf(3), stderr */
@ -68,14 +69,18 @@ static int write_flags = O_WRONLY | O_CREAT;
static void * static void *
Io_bufalloc(struct Io *io){ Io_bufalloc(struct Io *io){
return (io->buf = malloc(io->bs * (sizeof *io->buf))); return io != NULL
? (io->buf = malloc(io->bs * (sizeof *io->buf)))
: NULL;
} }
/* Fills the unused portion of io's buffer with padding, updating io->bufuse. /* Fills the unused portion of io's buffer with padding, updating io->bufuse.
* Returns io. */ * Returns io. */
static struct Io * static struct Io *
Io_bufrpad(struct Io *io, int padding){ Io_bufrpad(struct Io *io, int padding){
assert(io != NULL);
memset(io->buf + io->bufuse, padding, io->bs - io->bufuse); memset(io->buf + io->bufuse, padding, io->bs - io->bufuse);
io->bufuse = io->bs; io->bufuse = io->bs;