
spf at octo
Jan 23, 2011, 6:51 AM
Post #1 of 1
(909 views)
Permalink
|
|
[PATCH 2/2] spfquery: Simplify handling of the "result" buffer.
|
|
From: Florian Forster <ff [at] octo> This patch changes the "result" buffer to a character array of a fixed size. Also, the result is now printed as status0,status1,status2 instead of: status0status1status2 --- src/spfquery/spfquery.c | 33 ++++++++++++--------------------- 1 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/spfquery/spfquery.c b/src/spfquery/spfquery.c index 1904c8a..a93a81c 100644 --- a/src/spfquery/spfquery.c +++ b/src/spfquery/spfquery.c @@ -123,21 +123,16 @@ #define WARN_ERROR do { res = 255; } while(0) #define FAIL_ERROR do { res = 255; goto error; } while(0) -#define RESIZE_RESULT(n) do { \ - if (result == NULL) { \ - result_len = 256 + n; \ - result = malloc(result_len); \ - result[0] = '\0'; \ - } \ - else if (strlen(result) + n >= result_len) { \ - result_len = result_len + (result_len >> 1) + 8 + n; \ - result = realloc(result, result_len); \ - } \ -} while(0) -#define APPEND_RESULT(n) do { \ - partial_result = SPF_strresult(n); \ - RESIZE_RESULT(strlen(partial_result)); \ - strcat(result, partial_result); \ +#define APPEND_RESULT(n) do { \ + const char *partial_result = SPF_strresult(n); \ + if (result[0] == 0) { \ + strncpy (result, partial_result, sizeof (result)); \ + } else { \ + char tmp[sizeof (result)]; \ + strncpy (tmp, result, sizeof (tmp)); \ + snprintf (result, sizeof (result), "%s,%s", tmp, partial_result); \ + } \ + result[sizeof (result) - 1] = 0; \ } while(0) #define X_OR_EMPTY(x) ((x) ? (x) : "") @@ -354,9 +349,7 @@ int main( int argc, char *argv[] ) int res = 0; int c; - const char *partial_result; - char *result = NULL; - int result_len = 0; + char result[1024]; opts = (SPF_client_options_t *)malloc(sizeof(SPF_client_options_t)); memset(opts, 0, sizeof(SPF_client_options_t)); @@ -635,8 +628,7 @@ int main( int argc, char *argv[] ) CONTINUE_ERROR; } - if (result != NULL) - result[0] = '\0'; + memset (result, 0, sizeof (result)); APPEND_RESULT(SPF_response_result(spf_response)); if (req->rcpt_to != NULL && *req->rcpt_to != '\0' ) { @@ -704,7 +696,6 @@ int main( int argc, char *argv[] ) } error: - FREE(result, free); FREE_RESPONSE(spf_response); FREE_REQUEST(spf_request); FREE(spf_server, SPF_server_free); -- 1.7.2.3 ------------------------------------------- Sender Policy Framework: http://www.openspf.org [http://www.openspf.org] Modify Your Subscription: http://www.listbox.com/member/ [http://www.listbox.com/member/] Archives: https://www.listbox.com/member/archive/1007/=now RSS Feed: https://www.listbox.com/member/archive/rss/1007/1311533-9e42a648 Modify Your Subscription: https://www.listbox.com/member/?member_id=1311533&id_secret=1311533-d322f1f1 Unsubscribe Now: https://www.listbox.com/unsubscribe/?member_id=1311533&id_secret=1311533-d59c80a0&post_id=20110123095122:3C348BE6-2700-11E0-868A-E3C770647E91 Powered by Listbox: http://www.listbox.com
|