Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc: fix warnings with -O3 #4975

Closed
wants to merge 9 commits into from

Conversation

elliefm
Copy link
Contributor

@elliefm elliefm commented Jul 15, 2024

There's a bunch of compiler warnings that aren't detected unless certain optimisations are being performed. This PR fixes the warnings that turn up for me using GCC 12.2.0-14 on Debian Bookworm when compiling with -O3 in CFLAGS and CXXFLAGS. If you have a newer compiler to try with, it might find more.

@elliefm elliefm requested review from rsto and ksmurchison July 15, 2024 03:35
@elliefm elliefm added the backport-to-3.10 for PRs that are to be backported to 3.10 label Jul 15, 2024
@elliefm elliefm marked this pull request as draft July 15, 2024 03:46
@elliefm
Copy link
Contributor Author

elliefm commented Jul 15, 2024

Back to draft, gonna fix some that turn up with -D_FORTIFY_SOURCE too while I'm in here

@rsto
Copy link
Member

rsto commented Jul 15, 2024

I'm using the same compiler version.

@ksmurchison
Copy link
Contributor

ksmurchison commented Jul 15, 2024

I needed to add the patches below for GCC 13.3.1 and 14.1.1. The first to fix an uninitialized var complaint, and the second to fix a citem->s could be NULL complaint.

diff --git a/imap/httpd.c b/imap/httpd.c
index 9625c7c55..7c5372fbb 100644
--- a/imap/httpd.c
+++ b/imap/httpd.c
@@ -3035,7 +3035,7 @@ HIDDEN void log_request(long code, struct transaction_t *txn)
 EXPORTED void response_header(long code, struct transaction_t *txn)
 {
     int i, size;
-    time_t now;
+    time_t now = 0;
     char datestr[30];
     const char **hdr;
     struct auth_challenge_t *auth_chal = &txn->auth_chal;
diff --git a/imap/mbexamine.c b/imap/mbexamine.c
index 39eeb25ea..94da23eef 100644
--- a/imap/mbexamine.c
+++ b/imap/mbexamine.c
@@ -598,20 +598,24 @@ static int do_compare(struct findall_data *data, void *rock)
             r = record ? mailbox_cacherecord(mailbox, record) : -1;
 
             citem = r ? &empty_buf : cacheitem_buf(record, CACHE_FROM);
-            printf("   From: %-50.*s", (int) MIN(citem->len, 50), citem->s);
+            printf("   From: %-50.*s",
+                   (int) MIN(buf_len(citem), 50), buf_cstring(citem));
 
             if (fs_record.uid && !message_guid_isnull(&fs_record.guid)) {
                 citem = cacheitem_buf(&fs_record, CACHE_FROM);
-                printf("\t%-50.*s", (int) MIN(citem->len, 50), citem->s);
+                printf("\t%-50.*s",
+                       (int) MIN(buf_len(citem), 50), buf_cstring(citem));
             }
             printf("\n");
 
             citem = r ? &empty_buf : cacheitem_buf(record, CACHE_SUBJECT);
-            printf("   Subj: %-50.*s", (int) MIN(citem->len, 50), citem->s);
+            printf("   Subj: %-50.*s",
+                   (int) MIN(buf_len(citem), 50), buf_cstring(citem));
 
             if (fs_record.uid && !message_guid_isnull(&fs_record.guid)) {
                 citem = cacheitem_buf(&fs_record, CACHE_SUBJECT);
-                printf("\t%-50.*s", (int) MIN(citem->len, 50), citem->s);
+                printf("\t%-50.*s",
+                       (int) MIN(buf_len(citem), 50), buf_cstring(citem));
             }
             printf("\n");
             printf("\n");

Copy link
Contributor

@ksmurchison ksmurchison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add the diff that I supplied

@elliefm
Copy link
Contributor Author

elliefm commented Jul 16, 2024

Thanks!

Copy link
Contributor

@ksmurchison ksmurchison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WFM

@elliefm elliefm removed the backport-to-3.10 for PRs that are to be backported to 3.10 label Jul 19, 2024
@elliefm
Copy link
Contributor Author

elliefm commented Jul 19, 2024

I thought I was going to fix these warnings and then work on the actual problem separately, but the two wound up entangled and it no longer makes sense to keep them separate, so I'm closing this one off.

This work, as well as the actual bug fix, are now in #4980

@elliefm elliefm closed this Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants