]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Converted non-C compliant code to standard C. The usage of
authorNikos Mavrogiannopoulos <nmav@crystal.(none)>
Sat, 22 Nov 2008 22:13:31 +0000 (00:13 +0200)
committerNikos Mavrogiannopoulos <nmav@crystal.(none)>
Sat, 22 Nov 2008 22:13:31 +0000 (00:13 +0200)
structures like:

struct x {
  int el1;
  char str[1];
}

and the trick of using a single allocation for str and the structure
itself by allocating sizeof(x) + strlen()-1, are questionable. They
were converted to:

struct x {
  int el1;
  char *str;
}

and there is a single allocation of sizeof(x)+strlen() but then
the str pointer is updated to point to the rest of the data.

lib/opencdk/context.h
lib/opencdk/literal.c
lib/opencdk/misc.c
lib/opencdk/new-packet.c
lib/opencdk/opencdk.h
lib/opencdk/read-packet.c

index 71595a907ab2caaf110d7609db540914e3a58772..b695f0f45d4a4811347cbbe91f051efa85232c26 100644 (file)
@@ -99,7 +99,7 @@ struct cdk_subpkt_s {
   struct cdk_subpkt_s * next;
   u32 size;
   byte type;
-  byte d[1];  
+  byte *d;  
 };
 
 struct cdk_keylist_s {
@@ -121,7 +121,7 @@ struct cdk_dek_s {
 
 struct cdk_strlist_s {
   struct cdk_strlist_s * next;
-  char d[1]
+  char *d
 };
 
 #endif /* CDK_CONTEXT_H */
index aee17eea236d4c1db60bac9705abae2992d59588..fc4ee4fdc3407d57ff9e08bab345e8ffc28a1a84 100644 (file)
@@ -199,7 +199,8 @@ literal_encode (void *data, FILE * in, FILE * out)
 
   filelen = strlen (pfx->filename);
   cdk_pkt_new (&pkt);
-  pt = pkt->pkt.literal = cdk_calloc (1, sizeof *pt + filelen - 1);
+  pt = pkt->pkt.literal = cdk_calloc (1, sizeof *pt + filelen);
+  pt->name = pt + sizeof(*pt);
   if (!pt)
     {
       cdk_pkt_release (pkt);
index bc407b2052c089eda2a455d7cea897e598dce4f8..13e7fd5275581fdc669d4ca973edc5131a00fceb 100644 (file)
@@ -94,9 +94,10 @@ cdk_strlist_add (cdk_strlist_t * list, const char *string)
   if (!string)
     return NULL;
 
-  sl = cdk_calloc (1, sizeof *sl + strlen (string) + 1);
+  sl = cdk_calloc (1, sizeof *sl + strlen (string) + 2);
   if (!sl)
     return NULL;
+  sl->d = sl + sizeof(*sl);
   strcpy (sl->d, string);
   sl->next = *list;
   *list = sl;
index 9e788cd939ae7a11d8785ffebcab2b0d5e48bc8f..501d65293f0018a706512f044ecfe4484c6d12a1 100644 (file)
@@ -290,6 +290,7 @@ cdk_pkt_alloc (cdk_packet_t * r_pkt, cdk_packet_type_t pkttype)
       pkt->pkt.user_id = cdk_calloc (1, sizeof pkt->pkt.user_id);
       if (!pkt->pkt.user_id)
        return CDK_Out_Of_Core;
+      pkt->pkt.user_id->name = NULL;
       break;
 
     case CDK_PKT_PUBLIC_KEY:
@@ -338,6 +339,7 @@ cdk_pkt_alloc (cdk_packet_t * r_pkt, cdk_packet_type_t pkttype)
       pkt->pkt.literal = cdk_calloc (1, sizeof *pkt->pkt.literal);
       if (!pkt->pkt.literal)
        return CDK_Out_Of_Core;
+      pkt->pkt.literal->name = NULL;
       break;
 
     default:
@@ -383,9 +385,11 @@ _cdk_copy_userid (cdk_pkt_userid_t * dst, cdk_pkt_userid_t src)
     return CDK_Inv_Value;
 
   *dst = NULL;
-  u = cdk_calloc (1, sizeof *u + strlen (src->name) + 1);
+  u = cdk_calloc (1, sizeof *u + strlen (src->name) + 2);
   if (!u)
     return CDK_Out_Of_Core;
+  u->name = (void*)u + sizeof(*u);
+
   memcpy (u, src, sizeof *u);
   memcpy (u->name, src->name, strlen (src->name));
   u->prefs = _cdk_copy_prefs (src->prefs);
@@ -620,9 +624,11 @@ cdk_subpkt_new (size_t size)
 
   if (!size)
     return NULL;
-  s = cdk_calloc (1, sizeof *s + size + 1);
+  s = cdk_calloc (1, sizeof *s + size + 2);
   if (!s)
     return NULL;
+  s->d = (void*)s + sizeof(*s);
+
   return s;
 }
 
index 23c7bba9e8dfffe39129503643ba8a22f368a18d..0ba17af47a2318f94a4999e213896ba3213098be 100644 (file)
@@ -430,7 +430,7 @@ struct cdk_pkt_userid_s
   unsigned char *attrib_img;   /* Tag 17 if not null */
   size_t attrib_len;
   cdk_pkt_signature_t selfsig;
-  char name[1];
+  char *name;
 };
 typedef struct cdk_pkt_userid_s *cdk_pkt_userid_t;
 
@@ -538,7 +538,7 @@ struct cdk_pkt_literal_s
   int mode;
   unsigned int timestamp;
   int namelen;
-  char name[1];
+  char *name;
 };
 typedef struct cdk_pkt_literal_s *cdk_pkt_literal_t;
 
index cc3c40f2ba85e6a261d34b0dbd13b09ae643c4ab..2869c2ce053080629025f5b126d1764975d9480e 100644 (file)
@@ -833,9 +833,10 @@ read_literal (cdk_stream_t inp, size_t pktlen,
   pt->namelen = cdk_stream_getc (inp);
   if (pt->namelen > 0)
     {
-      *ret_pt = pt = cdk_realloc (pt, sizeof *pt + pt->namelen + 1);
+      *ret_pt = pt = cdk_realloc (pt, sizeof *pt + pt->namelen + 2);
       if (!pt)
        return CDK_Out_Of_Core;
+      pt->name = (void*)pt + sizeof(*pt);
       rc = stream_read (inp, pt->name, pt->namelen, &nread);
       if (rc)
        return rc;
@@ -997,15 +998,18 @@ cdk_pkt_read (cdk_stream_t inp, cdk_packet_t pkt)
                                     + pkt->pktlen + 16 + 1);
       if (!pkt->pkt.user_id)
        return CDK_Out_Of_Core;
+      pkt->pkt.user_id->name = (void*)pkt->pkt.user_id + sizeof(*pkt->pkt.user_id);
+
       rc = read_attribute (inp, pktlen, pkt->pkt.user_id);
       pkt->pkttype = CDK_PKT_ATTRIBUTE;
       break;
 
     case CDK_PKT_USER_ID:
       pkt->pkt.user_id = cdk_calloc (1, sizeof *pkt->pkt.user_id
-                                    + pkt->pktlen);
+                                    + pkt->pktlen + 1);
       if (!pkt->pkt.user_id)
        return CDK_Out_Of_Core;
+      pkt->pkt.user_id->name = (void*)pkt->pkt.user_id + sizeof(*pkt->pkt.user_id);
       rc = read_user_id (inp, pktlen, pkt->pkt.user_id);
       break;