summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/util/jedparse.cpp
diff options
context:
space:
mode:
author Vas Crabb <cuavas@users.noreply.github.com>2024-02-25 02:27:26 +1100
committer GitHub <noreply@github.com>2024-02-25 02:27:26 +1100
commit1615b8551a3a73532ac234973cfb04dd8ed98ba4 (patch)
tree25575506b4117afa614b94b4370af7f16eb9dbb5 /src/lib/util/jedparse.cpp
parent334ec12e0043ef939be418283235e3dbe5a005fe (diff)
util/ioprocs.cpp: Added wrappers for common patterns. (#11608)
emu/diimage.h: Removed fread overloads that allocate memory for output. util/core_file.cpp: Changed output size of load to size_t.
Diffstat (limited to 'src/lib/util/jedparse.cpp')
-rw-r--r--src/lib/util/jedparse.cpp24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/lib/util/jedparse.cpp b/src/lib/util/jedparse.cpp
index 5915886b1a6..b347a2dd2b5 100644
--- a/src/lib/util/jedparse.cpp
+++ b/src/lib/util/jedparse.cpp
@@ -24,6 +24,7 @@
#include <cstdlib>
#include <cstring>
#include <cctype>
+#include <tuple>
@@ -194,7 +195,6 @@ static void process_field(jed_data *data, const uint8_t *cursrc, const uint8_t *
int jed_parse(util::random_read &src, jed_data *result)
{
jed_parse_info pinfo;
- int i;
std::size_t actual;
std::error_condition err;
@@ -206,7 +206,7 @@ int jed_parse(util::random_read &src, jed_data *result)
uint8_t ch;
do
{
- err = src.read(&ch, 1, actual);
+ std::tie(err, actual) = read(src, &ch, 1);
if (err)
{
if (LOG_PARSE) printf("Read error searching for JED start marker\n");
@@ -225,7 +225,7 @@ int jed_parse(util::random_read &src, jed_data *result)
uint16_t checksum = ch;
do
{
- err = src.read(&ch, 1, actual);
+ std::tie(err, actual) = read(src, &ch, 1);
if (err)
{
if (LOG_PARSE) printf("Read error searching for JED end marker\n");
@@ -261,7 +261,8 @@ int jed_parse(util::random_read &src, jed_data *result)
/* see if there is a transmission checksum at the end */
uint8_t sumbuf[4];
- if (!src.read(&sumbuf[0], 4, actual) && actual == 4 && ishex(sumbuf[0]) && ishex(sumbuf[1]) && ishex(sumbuf[2]) && ishex(sumbuf[3]))
+ std::tie(err, actual) = read(src, &sumbuf[0], 4);
+ if (!err && (actual == 4) && ishex(sumbuf[0]) && ishex(sumbuf[1]) && ishex(sumbuf[2]) && ishex(sumbuf[3]))
{
uint16_t dessum = (hexval(sumbuf[0]) << 12) | (hexval(sumbuf[1]) << 8) | (hexval(sumbuf[2]) << 4) | hexval(sumbuf[3] << 0);
if (dessum != 0 && dessum != checksum)
@@ -281,7 +282,8 @@ int jed_parse(util::random_read &src, jed_data *result)
}
}
auto srcdata = std::make_unique<uint8_t[]>(endpos - startpos);
- if (src.read(&srcdata[0], endpos - startpos, actual) || actual != endpos - startpos)
+ std::tie(err, actual) = read(src, &srcdata[0], endpos - startpos);
+ if (err || ((endpos - startpos) != actual))
{
if (LOG_PARSE) printf("Error reading JED data\n");
return JEDERR_INVALID_DATA;
@@ -325,7 +327,7 @@ int jed_parse(util::random_read &src, jed_data *result)
/* validate the checksum */
checksum = 0;
- for (i = 0; i < (result->numfuses + 7) / 8; i++)
+ for (int i = 0; i < ((result->numfuses + 7) / 8); i++)
checksum += result->fusemap[i];
if (pinfo.checksum != 0 && checksum != pinfo.checksum)
{
@@ -441,13 +443,16 @@ size_t jed_output(const jed_data *data, void *result, size_t length)
int jedbin_parse(util::read_stream &src, jed_data *result)
{
+ std::error_condition err;
+ std::size_t actual;
+
/* initialize the output */
memset(result, 0, sizeof(*result));
/* need at least 4 bytes */
uint8_t buf[4];
- std::size_t actual;
- if (src.read(&buf[0], 4, actual) || actual != 4)
+ std::tie(err, actual) = read(src, &buf[0], 4);
+ if (err || (4 != actual))
return JEDERR_INVALID_DATA;
/* first unpack the number of fuses */
@@ -457,7 +462,8 @@ int jedbin_parse(util::read_stream &src, jed_data *result)
/* now make sure we have enough data in the source */
/* copy in the data */
- if (src.read(result->fusemap, (result->numfuses + 7) / 8, actual) || actual != (result->numfuses + 7) / 8)
+ std::tie(err, actual) = read(src, result->fusemap, (result->numfuses + 7) / 8);
+ if (err || (((result->numfuses + 7) / 8) != actual))
return JEDERR_INVALID_DATA;
return JEDERR_NONE;
}