ref: fc06f637cff6d812207fb798b48a31ab463f0ab5
parent: 917da0089dcaa013979a69aaeaeff0c08cbc7e26
author: cinap_lenrek <[email protected]>
date: Thu Sep 24 08:57:05 EDT 2015
libsec: cleanup newbytes()/newints()/newbits() and get rid of OFFSETOF() macro
--- a/sys/src/libsec/port/tlshand.c
+++ b/sys/src/libsec/port/tlshand.c
@@ -2948,8 +2948,6 @@
return (p[0]<<8)|p[1];
}
-#define OFFSET(x, s) offsetof(s, x)
-
static Bytes*
newbytes(int len)
{
@@ -2957,7 +2955,7 @@
if(len < 0)
abort();
- ans = (Bytes*)emalloc(OFFSET(data[0], Bytes) + len);
+ ans = emalloc(sizeof(Bytes) + len);
ans->len = len;
return ans;
}
@@ -2989,7 +2987,7 @@
if(len < 0 || len > ((uint)-1>>1)/sizeof(int))
abort();
- ans = (Ints*)emalloc(OFFSET(data[0], Ints) + len*sizeof(int));
+ ans = emalloc(sizeof(Ints) + len*sizeof(int));
ans->len = len;
return ans;
}
--- a/sys/src/libsec/port/x509.c
+++ b/sys/src/libsec/port/x509.c
@@ -3,9 +3,6 @@
#include <mp.h>
#include <libsec.h>
-/* ANSI offsetof, backwards. */
-#define OFFSETOF(a, b) offsetof(b, a)
-
/*=============================================================*/
/* general ASN1 declarations and parsing
*
@@ -61,13 +58,13 @@
struct Ints {
int len;
- int data[1];
+ int data[];
};
struct Bits {
int len; /* number of bytes */
int unusedbits; /* unused bits in last byte */
- uchar data[1]; /* most-significant bit first */
+ uchar data[]; /* most-significant bit first */
};
struct Tag {
@@ -1288,7 +1285,7 @@
if(len < 0)
abort();
- ans = (Bytes*)emalloc(OFFSETOF(data[0], Bytes) + len);
+ ans = emalloc(sizeof(Bytes) + len);
ans->len = len;
return ans;
}
@@ -1349,7 +1346,7 @@
if(len < 0 || len > ((uint)-1>>1)/sizeof(int))
abort();
- ans = (Ints*)emalloc(OFFSETOF(data[0], Ints) + len*sizeof(int));
+ ans = emalloc(sizeof(Ints) + len*sizeof(int));
ans->len = len;
return ans;
}
@@ -1378,7 +1375,7 @@
if(len < 0)
abort();
- ans = (Bits*)emalloc(OFFSETOF(data[0], Bits) + len);
+ ans = emalloc(sizeof(Bits) + len);
ans->len = len;
ans->unusedbits = 0;
return ans;