libsec: cleanup newbytes()/newints()/newbits() and get rid of OFFSETOF() macro

This commit is contained in:
cinap_lenrek 2015-09-24 12:57:05 +02:00
parent 917da0089d
commit fc06f637cf
2 changed files with 7 additions and 12 deletions

View file

@ -2948,8 +2948,6 @@ get16(uchar *p)
return (p[0]<<8)|p[1]; return (p[0]<<8)|p[1];
} }
#define OFFSET(x, s) offsetof(s, x)
static Bytes* static Bytes*
newbytes(int len) newbytes(int len)
{ {
@ -2957,7 +2955,7 @@ newbytes(int len)
if(len < 0) if(len < 0)
abort(); abort();
ans = (Bytes*)emalloc(OFFSET(data[0], Bytes) + len); ans = emalloc(sizeof(Bytes) + len);
ans->len = len; ans->len = len;
return ans; return ans;
} }
@ -2989,7 +2987,7 @@ newints(int len)
if(len < 0 || len > ((uint)-1>>1)/sizeof(int)) if(len < 0 || len > ((uint)-1>>1)/sizeof(int))
abort(); abort();
ans = (Ints*)emalloc(OFFSET(data[0], Ints) + len*sizeof(int)); ans = emalloc(sizeof(Ints) + len*sizeof(int));
ans->len = len; ans->len = len;
return ans; return ans;
} }

View file

@ -3,9 +3,6 @@
#include <mp.h> #include <mp.h>
#include <libsec.h> #include <libsec.h>
/* ANSI offsetof, backwards. */
#define OFFSETOF(a, b) offsetof(b, a)
/*=============================================================*/ /*=============================================================*/
/* general ASN1 declarations and parsing /* general ASN1 declarations and parsing
* *
@ -61,13 +58,13 @@ struct Bytes {
struct Ints { struct Ints {
int len; int len;
int data[1]; int data[];
}; };
struct Bits { struct Bits {
int len; /* number of bytes */ int len; /* number of bytes */
int unusedbits; /* unused bits in last byte */ int unusedbits; /* unused bits in last byte */
uchar data[1]; /* most-significant bit first */ uchar data[]; /* most-significant bit first */
}; };
struct Tag { struct Tag {
@ -1288,7 +1285,7 @@ newbytes(int len)
if(len < 0) if(len < 0)
abort(); abort();
ans = (Bytes*)emalloc(OFFSETOF(data[0], Bytes) + len); ans = emalloc(sizeof(Bytes) + len);
ans->len = len; ans->len = len;
return ans; return ans;
} }
@ -1349,7 +1346,7 @@ newints(int len)
if(len < 0 || len > ((uint)-1>>1)/sizeof(int)) if(len < 0 || len > ((uint)-1>>1)/sizeof(int))
abort(); abort();
ans = (Ints*)emalloc(OFFSETOF(data[0], Ints) + len*sizeof(int)); ans = emalloc(sizeof(Ints) + len*sizeof(int));
ans->len = len; ans->len = len;
return ans; return ans;
} }
@ -1378,7 +1375,7 @@ newbits(int len)
if(len < 0) if(len < 0)
abort(); abort();
ans = (Bits*)emalloc(OFFSETOF(data[0], Bits) + len); ans = emalloc(sizeof(Bits) + len);
ans->len = len; ans->len = len;
ans->unusedbits = 0; ans->unusedbits = 0;
return ans; return ans;