[balsa] imap-handle: use a flexible array member



commit 46665e582cbf5bc78e90c2ec9425b221ba60a87c
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Sat Mar 27 18:52:30 2021 -0400

    imap-handle: use a flexible array member
    
    to append data to struct ImapMsgSerialized.
    
    Thanks to @albrecht for the suggestion and reference to the C99 standard,
    in https://gitlab.gnome.org/GNOME/balsa/-/issues/57
    
    * libbalsa/imap/imap-handle.c:
      struct ImapMsgSerialized: replace
        - gchar fetched_headers_first_char;
        with a flexible array member
        + gchar fetched_headers_data[];
      (imap_message_serialize): adapt to the change;
      (imap_message_deserialize): ditto.

 ChangeLog                   | 17 +++++++++++++++++
 libbalsa/imap/imap-handle.c |  8 ++++----
 2 files changed, 21 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1f737f9ac..7c4ce6c7b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2021-03-27  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       imap-handle: use a flexible array member
+
+       to append data to struct ImapMsgSerialized.
+
+       Thanks to @albrecht for the suggestion and reference to the C99
+       standard, in https://gitlab.gnome.org/GNOME/balsa/-/issues/57
+
+       * libbalsa/imap/imap-handle.c:
+         struct ImapMsgSerialized: replace
+           - gchar fetched_headers_first_char;
+           with a flexible array member
+           + gchar fetched_headers_data[];
+         (imap_message_serialize): adapt to the change;
+         (imap_message_deserialize): ditto.
+
 2021-03-25  Peter Bloomfield  <pbloomfield bellsouth net>
 
        html: WebKit deprecation cleanup
diff --git a/libbalsa/imap/imap-handle.c b/libbalsa/imap/imap-handle.c
index 1e3b0cab3..1ac4b8114 100644
--- a/libbalsa/imap/imap-handle.c
+++ b/libbalsa/imap/imap-handle.c
@@ -1658,7 +1658,7 @@ struct ImapMsgSerialized {
   ImapDate     internal_date; /* delivery date */
   int rfc822size;
   ImapFetchType available_headers;
-  gchar fetched_headers_first_char;
+  gchar fetched_headers_data[];
 };
 
 void*
@@ -1676,7 +1676,7 @@ imap_message_serialize(ImapMessage *imsg)
   strings[0] = imsg->fetched_header_fields;
   strings[1] = imap_envelope_to_string(imsg->envelope);
   strings[2] = imap_body_to_string(imsg->body);
-  tot_size = sizeof(struct ImapMsgSerialized)-1;
+  tot_size = sizeof(struct ImapMsgSerialized);
   for(i=0; i<3; i++) {
     lengths[i] = strings[i]  ? strlen(strings[i])  : 0;
     tot_size += lengths[i] + 1;
@@ -1691,7 +1691,7 @@ imap_message_serialize(ImapMessage *imsg)
   imes->rfc822size    = imsg->rfc822size;
   imes->available_headers = imsg->available_headers;
 
-  ptr = &imes->fetched_headers_first_char;
+  ptr = imes->fetched_headers_data;
   for(i=0; i<3; i++) {
     if(strings[i])
       strcpy(ptr, strings[i]);
@@ -1719,7 +1719,7 @@ imap_message_deserialize(void *data)
   imsg->rfc822size = imes->rfc822size;
   imsg->available_headers = imes->available_headers;
   /* Envelope */
-  ptr = &imes->fetched_headers_first_char;
+  ptr = imes->fetched_headers_data;
   imsg->fetched_header_fields = *ptr ? g_strdup(ptr) : NULL;
   ptr += strlen(ptr) + 1;
   imsg->envelope = imap_envelope_from_string(ptr);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]