Fix calling convention of huri_field_escape
PATCH 1/1 Fix calling convention of huri_field_escape
Premature optimization is the root of all evil.
Use a sensible convention of not screwing with the argument, at the expense of extra strdup.
Fortunately, all users are confined to Hail itself, even if huri_field_escape is exported.
Signed-off-by Pete Zaitcev <[email protected]>
--- include/hstor.h | 2 +- lib/hstor.c | 44 +++++++++++++++++++++++++++++--------------- lib/huri.c | 10 +++++----- 3 files changed, 35 insertions(+), 21 deletions(-)
include/hstor.h +1 -1
@@ -144,7 +144,7 @@ extern int hreq_acl_canned(struct http_req *req);/* uri.c */ extern struct http_uri *huri_parse (struct http_uri *uri_dest,char *uri_src_text);extern int huri_field_unescape (char *s,int s_len); -extern char *huri_field_escape (char *signed_str,unsigned char mask); +extern char *huri_field_escape (const char *signed_str,unsigned char mask);static inline bool hreq_http11 (struct http_req *req) {
lib/hstor.c +29 -15
126 lines not on this page · raw message
lib/huri.c +5 -5
@@ -25,7 +25,6 @@#include <string.h> #include <ctype.h> #include <stdbool.h> -#include <glib.h> #include <hstor.h> /* our own ISSPACE. ANSI isspace is locale dependent */
@@ -221,7 +220,7 @@ static const guchar neednt_escape_table[] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -char *huri_field_escape (char *signed_str,unsigned char mask) +char *huri_field_escape (const char *signed_str,unsigned char mask) {int len;int i;
@@ -250,10 +249,12 @@ char* huri_field_escape (char *signed_str, unsigned char mask)/* Don't escape if unnecessary */ if (must_escape == FALSE) -return signed_str; +return strdup (signed_str);/* Allocate buffer */ - dst = (gchar *)g_malloc (len +1 ); + dst =malloc (len +1 ); +if (!dst) +return NULL ;/* Copy */ for (i = j =0 ; str[i]; i++, j++)
@@ -284,7 +285,6 @@ char* huri_field_escape (char *signed_str, unsigned char mask) } dst[j] ='\0' ; -g_free (signed_str);return dst; }
Jeff Garzik
AppliedQuoted 8 lines · Pete Zaitcev
Premature optimization is the root of all evil.
Use a sensible convention of not screwing with the argument, at the expense of extra strdup.
Fortunately, all users are confined to Hail itself, even if
huri_field_escapeis exported.
Quoted 7 lines
Signed-off-by Pete Zaitcev<[email protected]>--- include/hstor.h | 2 +- lib/hstor.c | 44 +++++++++++++++++++++++++++++--------------- lib/huri.c | 10 +++++----- 3 files changed, 35 insertions(+), 21 deletions(-)
applied