Allocator sizeof operand mismatch (src/backend/regex/regcomp.c)
Hi,
About the error:
Result of 'malloc' is converted to a pointer of type 'char', which is
incompatible with sizeof operand type 'struct guts'
The patch attached tries to fix this.
regards,
Ranier Vilela
Attachments:
001-fix-allocator-sizeof-operand-mismatch.patchtext/x-patch; charset=US-ASCII; name=001-fix-allocator-sizeof-operand-mismatch.patchDownload
diff --git a/src/backend/regex/regcomp.c b/src/backend/regex/regcomp.c
index 473738040b..56e5ab1e84 100644
--- a/src/backend/regex/regcomp.c
+++ b/src/backend/regex/regcomp.c
@@ -389,7 +389,7 @@ pg_regcomp(regex_t *re,
re->re_fns = VS(&functions);
/* more complex setup, malloced things */
- re->re_guts = VS(MALLOC(sizeof(struct guts)));
+ re->re_guts = (struct guts *) MALLOC(sizeof(struct guts));
if (re->re_guts == NULL)
return freev(v, REG_ESPACE);
g = (struct guts *) re->re_guts;
I think it’s ok, re_guts is converted when used
(struct guts *) re->re_guts;
And there is comments in regex.h
char *re_guts; /* `char *' is more portable than `void *' */
Regards,
Zhang Mingli
Show quoted text
On Aug 6, 2022, 20:13 +0800, Ranier Vilela <ranier.vf@gmail.com>, wrote:
Hi,
About the error:
Result of 'malloc' is converted to a pointer of type 'char', which is incompatible with sizeof operand type 'struct guts'The patch attached tries to fix this.
regards,
Ranier Vilela
Zhang Mingli <zmlpostgres@gmail.com> writes:
I think it’s ok, re_guts is converted when used
(struct guts *) re->re_guts;
And there is comments in regex.h
char *re_guts; /* `char *' is more portable than `void *' */
Boy, that comment is showing its age isn't it? If we were to do
anything about this, I'd be more inclined to change re_guts to void*.
But, never having seen any compiler warnings about this code,
I don't feel a strong need to do something.
regards, tom lane
On Aug 6, 2022, 22:47 +0800, Tom Lane <tgl@sss.pgh.pa.us>, wrote:
Zhang Mingli <zmlpostgres@gmail.com> writes:
I think it’s ok, re_guts is converted when used
(struct guts *) re->re_guts;
And there is comments in regex.h
char *re_guts; /* `char *' is more portable than `void *' */Boy, that comment is showing its age isn't it? If we were to do
anything about this, I'd be more inclined to change re_guts to void*.
Got it , thanks.