unsigned char * is allowed to alias, so we use that for byte reversing
rather than uint32_t. This is portable.
Remove warnings about ignoring pread/pwrite return values.
And initialize tdb before setjmp: with optimization, gcc validly saw this
as NULL and crashed.
/* Endian conversion: we only ever deal with 4 byte quantities */
void *tdb_convert(void *buf, uint32_t size)
{
/* Endian conversion: we only ever deal with 4 byte quantities */
void *tdb_convert(void *buf, uint32_t size)
{
- uint32_t i, *p = (uint32_t *)buf;
- for (i = 0; i < size / 4; i++)
- p[i] = TDB_BYTEREV(p[i]);
+ uint32_t i;
+ unsigned char *p = buf, tmp;
+
+ for (i = 0; i < size; i += 4) {
+ tmp = p[i];
+ p[i] = p[i+3];
+ p[i+3] = tmp;
+ tmp = p[i+1];
+ p[i+1] = p[i+2];
+ p[i+2] = tmp;
+ }
((unsigned char *)tdb->map_ptr)[off] ^= mask;
else {
unsigned char c;
((unsigned char *)tdb->map_ptr)[off] ^= mask;
else {
unsigned char c;
- pread(tdb->fd, &c, 1, off);
+ if (pread(tdb->fd, &c, 1, off) != 1)
+ err(1, "pread");
- pwrite(tdb->fd, &c, 1, off);
+ if (pwrite(tdb->fd, &c, 1, off) != 1)
+ err(1, "pwrite");
current = target = 0;
reset:
current = target = 0;
reset:
+ unlink(TEST_DBNAME);
+ tdb = tdb_open_ex(TEST_DBNAME, 1024, TDB_NOMMAP,
+ O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
+
if (setjmp(jmpbuf) != 0) {
/* We're partway through. Simulate our death. */
close(tdb->fd);
if (setjmp(jmpbuf) != 0) {
/* We're partway through. Simulate our death. */
close(tdb->fd);
- unlink(TEST_DBNAME);
- tdb = tdb_open_ex(TEST_DBNAME, 1024, TDB_NOMMAP,
- O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
-
/* Put key for agent to fetch. */
key.dsize = strlen(KEY_STRING);
key.dptr = (void *)KEY_STRING;
/* Put key for agent to fetch. */
key.dsize = strlen(KEY_STRING);
key.dptr = (void *)KEY_STRING;