aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2021-08-06 21:07:08 +0100
committerTomasz Kramkowski <tk@the-tk.com>2021-08-06 21:07:08 +0100
commit2e73916323acd066c7319f65ecddd5d4a15bc1f3 (patch)
tree48c2c8dd897c4410626d98eaada1380e11f64d33
parentcf494b1359b07f809cd9ec6b653e41d2366cf00e (diff)
downloadpack-2e73916323acd066c7319f65ecddd5d4a15bc1f3.tar.gz
pack-2e73916323acd066c7319f65ecddd5d4a15bc1f3.tar.xz
pack-2e73916323acd066c7319f65ecddd5d4a15bc1f3.zip
fix up missed pack_type chars
-rw-r--r--pack.c2
-rw-r--r--unpack.c23
2 files changed, 14 insertions, 11 deletions
diff --git a/pack.c b/pack.c
index f06aafe..002d1ee 100644
--- a/pack.c
+++ b/pack.c
@@ -44,7 +44,7 @@ enum pack_status pack(void *buf_, size_t size, const char *fmt, ...)
break;
ITYPE_MACROS
#undef T
- case 'x': v.unsigned_ = 0; sign = false; break;
+ case PACK_TYPE_PADDING: v.unsigned_ = 0; sign = false; break;
default: return PACK_FMTINVAL;
}
tr_debug("i: %d, fmt[i]: %c, sign: %ssigned", i, fmt[i], sign ? "" : "un");
diff --git a/unpack.c b/unpack.c
index c33ff36..472cc8c 100644
--- a/unpack.c
+++ b/unpack.c
@@ -50,6 +50,7 @@ enum pack_status unpack(const void *buf_, size_t size, const char *fmt, ...)
for (int i = 0; fmt[i] != '\0'; i++) {
bool sign;
size_t count = 1, s;
+ enum pack_type t;
union {
#define T(type, sign, c_type, va_type) \
sign c_type *type;
@@ -91,19 +92,20 @@ enum pack_status unpack(const void *buf_, size_t size, const char *fmt, ...)
break;
ITYPE_MACROS
#undef T
- case 'f': arg.f = va_arg(ap, float *); break;
- case 'd': arg.d = va_arg(ap, double *); break;
- case 'x': break;
+ case PACK_TYPE_FLOAT: arg.f = va_arg(ap, float *); break;
+ case PACK_TYPE_DOUBLE: arg.d = va_arg(ap, double *); break;
+ case PACK_TYPE_PADDING: break;
default: return PACK_FMTINVAL;
}
+ t = fmt[i];
- s = getsize(fmt[i]);
+ s = getsize(t);
tr_debug("s: %" PRIuSIZE, s);
if (s == (size_t)-1) return PACK_FMTINVAL;
if (size - offset < s * count) return PACK_TOOSMALL;
- if (fmt[i] == 'x') goto skip;
+ if (t == PACK_TYPE_PADDING) goto skip;
for (size_t j = 0; j < count; j++) {
val.unsigned_ =
@@ -111,11 +113,11 @@ enum pack_status unpack(const void *buf_, size_t size, const char *fmt, ...)
tr_debug("val.u: %" PRIuMAX ", at: %" PRIuSIZE,
val.unsigned_, offset + s * j);
- if (fmt[i] == 'f') {
+ if (t == PACK_TYPE_FLOAT) {
float f = ieee754b32_deserialise(val.unsigned_);
val.f = f;
tr_debug("val.f: %f", val.f);
- } else if (fmt[i] == 'd') {
+ } else if (t == PACK_TYPE_DOUBLE) {
double d = ieee754b64_deserialise(val.unsigned_);
val.d = d;
tr_debug("val.d: %f", val.d);
@@ -131,15 +133,16 @@ enum pack_status unpack(const void *buf_, size_t size, const char *fmt, ...)
tr_debug("val.s: %" PRIdMAX, val.signed_);
}
- switch (fmt[i]) {
+ switch (t) {
#define T(type, sign, c_type, va_type) \
case (char)PACK_TYPE_##type: \
arg.type[j] = val.sign##_; \
break;
ITYPE_MACROS
#undef T
- case 'f': arg.f[j] = val.f; break;
- case 'd': arg.d[j] = val.d; break;
+ case PACK_TYPE_FLOAT: arg.f[j] = val.f; break;
+ case PACK_TYPE_DOUBLE: arg.d[j] = val.d; break;
+ case PACK_TYPE_PADDING: break;
}
}
skip: