summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2015-09-24 12:57:05 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2015-09-24 12:57:05 +0200
commitfc06f637cff6d812207fb798b48a31ab463f0ab5 (patch)
tree8aecca0a24cdc122f0b17448689cf31fae2650c6
parent917da0089dcaa013979a69aaeaeff0c08cbc7e26 (diff)
libsec: cleanup newbytes()/newints()/newbits() and get rid of OFFSETOF() macro
-rw-r--r--sys/src/libsec/port/tlshand.c6
-rw-r--r--sys/src/libsec/port/x509.c13
2 files changed, 7 insertions, 12 deletions
diff --git a/sys/src/libsec/port/tlshand.c b/sys/src/libsec/port/tlshand.c
index bc6506704..bd659e86a 100644
--- a/sys/src/libsec/port/tlshand.c
+++ b/sys/src/libsec/port/tlshand.c
@@ -2948,8 +2948,6 @@ get16(uchar *p)
return (p[0]<<8)|p[1];
}
-#define OFFSET(x, s) offsetof(s, x)
-
static Bytes*
newbytes(int len)
{
@@ -2957,7 +2955,7 @@ newbytes(int len)
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 @@ newints(int len)
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;
}
diff --git a/sys/src/libsec/port/x509.c b/sys/src/libsec/port/x509.c
index 4e0bf2a9c..1b84ad89a 100644
--- 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 Bytes {
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 @@ newbytes(int len)
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 @@ newints(int len)
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 @@ newbits(int len)
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;