#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: cdf.c,v 1.46 2011/09/16 21:23:59 christos Exp $")
+FILE_RCSID("@(#)$File: cdf.c,v 1.47 2012/02/17 04:23:30 christos Exp $")
#endif
#include <assert.h>
cdf_read_short_sector(const cdf_stream_t *sst, void *buf, size_t offs,
size_t len, const cdf_header_t *h, cdf_secid_t id)
{
- size_t ss = CDF_SHORT_SEC_SIZE(h);
+ size_t ss = CDF_SEC_SIZE(h);
size_t pos = CDF_SHORT_SEC_POS(h, id);
assert(ss == len);
- if (sst->sst_len < (size_t)id) {
- DPRINTF(("bad sector id %d > %d\n", id, sst->sst_len));
+ if (pos > ss * sst->sst_len) {
+ DPRINTF(("Out of bounds read %" SIZE_T_FORMAT "u > %"
+ SIZE_T_FORMAT "u\n",
+ pos, ss * sst->sst_len));
return -1;
}
(void)memcpy(((char *)buf) + offs,
if (sec < 0)
goto out;
if (i >= sat->sat_len) {
- DPRINTF(("Out of bounds reading MSA %u >= %u",
- i, sat->sat_len));
+ DPRINTF(("Out of bounds reading MSA %" SIZE_T_FORMAT
+ "u >= %" SIZE_T_FORMAT "u", i, sat->sat_len));
errno = EFTYPE;
goto out2;
}
}
if (i >= scn->sst_len) {
DPRINTF(("Out of bounds reading long sector chain "
- "%u > %u\n", i, scn->sst_len));
+ "%" SIZE_T_FORMAT "u > %" SIZE_T_FORMAT "u\n", i,
+ scn->sst_len));
errno = EFTYPE;
goto out;
}
const cdf_sat_t *ssat, const cdf_stream_t *sst,
cdf_secid_t sid, size_t len, cdf_stream_t *scn)
{
- size_t ss = CDF_SHORT_SEC_SIZE(h), i, j;
+ size_t ss = CDF_SEC_SIZE(h), i, j;
scn->sst_len = cdf_count_chain(ssat, sid, CDF_SEC_SIZE(h));
scn->sst_dirlen = len;
}
if (i >= scn->sst_len) {
DPRINTF(("Out of bounds reading short sector chain "
- "%u > %u\n", i, scn->sst_len));
+ "%" SIZE_T_FORMAT "u > %" SIZE_T_FORMAT "u\n",
+ i, scn->sst_len));
errno = EFTYPE;
goto out;
}
}
if (i >= ssat->sat_len) {
DPRINTF(("Out of bounds reading short sector chain "
- "%u > %u\n", i, ssat->sat_len));
+ "%" SIZE_T_FORMAT "u > %" SIZE_T_FORMAT "u\n", i,
+ ssat->sat_len));
errno = EFTYPE;
goto out;
}
}
inp[i].pi_id = CDF_GETUINT32(p, i << 1);
inp[i].pi_type = CDF_GETUINT32(q, 0);
- DPRINTF(("%d) id=%x type=%x offs=%x,%d\n", i, inp[i].pi_id,
- inp[i].pi_type, q - p, CDF_GETUINT32(p, (i << 1) + 1)));
+ DPRINTF(("%" SIZE_T_FORMAT "u) id=%x type=%x offs=%tx,%d\n", i,
+ inp[i].pi_id, inp[i].pi_type, q - p,
+ CDF_GETUINT32(p, (i << 1) + 1)));
if (inp[i].pi_type & CDF_VECTOR) {
nelements = CDF_GETUINT32(q, 1);
o = 2;
(void)memcpy(&u64, &q[o4], sizeof(u64));
inp[i].pi_u64 = CDF_TOLE8((uint64_t)u64);
break;
+ case CDF_FLOAT:
+ if (inp[i].pi_type & CDF_VECTOR)
+ goto unknown;
+ (void)memcpy(&u32, &q[o4], sizeof(u32));
+ u32 = CDF_TOLE4(u32);
+ memcpy(&inp[i].pi_f, &u32, sizeof(inp[i].pi_f));
+ break;
+ case CDF_DOUBLE:
+ if (inp[i].pi_type & CDF_VECTOR)
+ goto unknown;
+ (void)memcpy(&u64, &q[o4], sizeof(u64));
+ u64 = CDF_TOLE8((uint64_t)u64);
+ memcpy(&inp[i].pi_d, &u64, sizeof(inp[i].pi_d));
+ break;
case CDF_LENGTH32_STRING:
case CDF_LENGTH32_WSTRING:
if (nelements > 1) {
*info = inp;
inp = *info + nelem;
}
- DPRINTF(("nelements = %d\n", nelements));
+ DPRINTF(("nelements = %" SIZE_T_FORMAT "u\n",
+ nelements));
for (j = 0; j < nelements; j++, i++) {
uint32_t l = CDF_GETUINT32(q, o);
inp[i].pi_str.s_len = l;
inp[i].pi_str.s_buf = (const char *)
(const void *)(&q[o4 + sizeof(l)]);
- DPRINTF(("l = %d, r = %d, s = %s\n", l,
+ DPRINTF(("l = %d, r = %" SIZE_T_FORMAT
+ "u, s = %s\n", l,
CDF_ROUND(l, sizeof(l)),
inp[i].pi_str.s_buf));
l = 4 + (uint32_t)CDF_ROUND(l, sizeof(l));
unknown:
DPRINTF(("Don't know how to deal with %x\n",
inp[i].pi_type));
- goto out;
+ break;
}
}
return 0;
return -1;
}
if (cdf_read_property_info(sst, h, CDF_TOLE4(sd->sd_offset),
- info, count, &maxcount) == -1)
+ info, count, &maxcount) == -1) {
return -1;
+ }
}
return 0;
}
size_t i, j, s = size / sizeof(cdf_secid_t);
for (i = 0; i < sat->sat_len; i++) {
- (void)fprintf(stderr, "%s[%" SIZE_T_FORMAT "u]:\n%.6d: ",
- prefix, i, i * s);
+ (void)fprintf(stderr, "%s[%" SIZE_T_FORMAT "u]:\n%.6"
+ SIZE_T_FORMAT "u: ", prefix, i, i * s);
for (j = 0; j < s; j++) {
(void)fprintf(stderr, "%5d, ",
CDF_TOLE4(sat->sat_tab[s * i + j]));
if ((j + 1) % 10 == 0)
- (void)fprintf(stderr, "\n%.6d: ",
- i * s + j + 1);
+ (void)fprintf(stderr, "\n%.6" SIZE_T_FORMAT
+ "u: ", i * s + j + 1);
}
(void)fprintf(stderr, "\n");
}
if (j == 16) {
j = 0;
abuf[15] = '\0';
- (void)fprintf(stderr, "%s\n%.4x: ", abuf, i + 1);
+ (void)fprintf(stderr, "%s\n%.4" SIZE_T_FORMAT "x: ",
+ abuf, i + 1);
}
}
(void)fprintf(stderr, "\n");
(void)fprintf(stderr, "unsigned 32 [%u]\n",
info[i].pi_u32);
break;
+ case CDF_FLOAT:
+ (void)fprintf(stderr, "float [%g]\n",
+ info[i].pi_f);
+ break;
+ case CDF_DOUBLE:
+ (void)fprintf(stderr, "double [%g]\n",
+ info[i].pi_d);
+ break;
case CDF_LENGTH32_STRING:
(void)fprintf(stderr, "string %u [%.*s]\n",
info[i].pi_str.s_len,