From 052172252596d4afca1242bae76b48e7c0079f1e Mon Sep 17 00:00:00 2001 From: "Howard M. Harte" Date: Sat, 1 Apr 2023 07:01:12 -0700 Subject: [PATCH] AltairZ80: Resolve warnings in Flashwriter and Disk3. --- AltairZ80/flashwriter2.c | 11 +++++++++-- AltairZ80/s100_disk3.c | 13 ++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/AltairZ80/flashwriter2.c b/AltairZ80/flashwriter2.c index 82fbbde5..2983cb0f 100644 --- a/AltairZ80/flashwriter2.c +++ b/AltairZ80/flashwriter2.c @@ -1,6 +1,6 @@ /************************************************************************* * * - * Copyright (c) 2007-2022 Howard M. Harte. * + * Copyright (c) 2007-2023 Howard M. Harte. * * https://github.com/hharte * * * * Permission is hereby granted, free of charge, to any person obtaining * @@ -138,6 +138,11 @@ static t_stat fw2_attach(UNIT *uptr, CONST char *cptr) } fw2_info[i] = (FW2_INFO *)calloc(1, sizeof(FW2_INFO)); + + if (fw2_info[i] == NULL) { + return SCPE_MEM; + } + fw2_info[i]->uptr = uptr; fw2_info[i]->uptr->u3 = baseaddr; @@ -200,7 +205,9 @@ static t_stat fw2_detach(UNIT *uptr) static t_stat get_base_address(const char *cptr, uint32 *baseaddr) { uint32 b; - sscanf(cptr, "%x", &b); + + if (sscanf(cptr, "%x", &b) != 1) return SCPE_ARG; + if(b & (FW2_CAPACITY-1)) { sim_printf("FWII must be on a %d-byte boundary.\n", FW2_CAPACITY); return SCPE_ARG; diff --git a/AltairZ80/s100_disk3.c b/AltairZ80/s100_disk3.c index 046fad42..5d026527 100644 --- a/AltairZ80/s100_disk3.c +++ b/AltairZ80/s100_disk3.c @@ -1,6 +1,6 @@ /************************************************************************* * * - * Copyright (c) 2007-2022 Howard M. Harte. * + * Copyright (c) 2007-2023 Howard M. Harte. * * https://github.com/hharte * * * * Permission is hereby granted, free of charge, to any person obtaining * @@ -537,6 +537,11 @@ static uint8 DISK3_Write(const uint32 Addr, uint8 cData) dataBuffer = (uint8 *)malloc(xfr_len); + if (dataBuffer == NULL) { + sim_printf("%s: memory allocation failure.\n", sim_uname(pDrive->uptr)); + break; + } + if(sim_fseek((pDrive->uptr)->fileref, file_offset, SEEK_SET) == 0) { if(disk3_info->iopb[DISK3_IOPB_ARG1] == 1) { /* Read */ @@ -615,6 +620,12 @@ static uint8 DISK3_Write(const uint32 Addr, uint8 cData) file_offset += (disk3_info->iopb[DISK3_IOPB_ARG3] * data_len); fmtBuffer = (uint8 *)malloc(data_len); + + if (fmtBuffer == NULL) { + sim_printf("%s: memory allocation failure.\n", sim_uname(pDrive->uptr)); + break; + } + memset(fmtBuffer, disk3_info->iopb[DISK3_IOPB_ARG2], data_len); if(sim_fseek((pDrive->uptr)->fileref, file_offset, SEEK_SET) == 0) {