Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8bdb36a

Browse files
committed
Clean up some questionable usages of DatumGet* macros
This tidies up some questionable coding which made use ofDatumGetPointer() for Datums being passed into functions where theparameter is expected to be a cstring. We saw no compiler warnings withthe old code as the Pointer type used in DatumGetPointer() happens tobe a char * rather than a void *. However, that's no excuse and we shouldbe using the correct macro for the job.Here we also make use of OutputFunctionCall() rather than usingFunctionCall1() directly to call the type's output function.OutputFunctionCall() is the standard way to do this. It casts thereturned value to a cstring for us.In passing get rid of a duplicate call to strlen(). Most compilers willlikely optimize away the 2nd call, but there may be some that won't. Inany case, this just aligns the code to some other nearby code that alreadydoes this.Discussion:https://postgr.es/m/CAApHDvq1D=ehZ8hey8Hz67N+_Zth0GHO5wiVCfv1YcGPMXJq0A@mail.gmail.com
1 parente453938 commit8bdb36a

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

‎src/backend/access/brin/brin_minmax_multi.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ range_serialize(Ranges *range)
634634
for (i=0;i<nvalues;i++)
635635
{
636636
/* don't forget to include the null terminator ;-) */
637-
len+=strlen(DatumGetPointer(range->values[i]))+1;
637+
len+=strlen(DatumGetCString(range->values[i]))+1;
638638
}
639639
}
640640
else/* fixed-length types (even by-reference) */
@@ -695,9 +695,9 @@ range_serialize(Ranges *range)
695695
}
696696
elseif (typlen==-2)/* cstring */
697697
{
698-
inttmp=strlen(DatumGetPointer(range->values[i]))+1;
698+
inttmp=strlen(DatumGetCString(range->values[i]))+1;
699699

700-
memcpy(ptr,DatumGetPointer(range->values[i]),tmp);
700+
memcpy(ptr,DatumGetCString(range->values[i]),tmp);
701701
ptr+=tmp;
702702
}
703703

@@ -780,8 +780,10 @@ range_deserialize(int maxvalues, SerializedRanges *serialized)
780780
}
781781
elseif (typlen==-2)/* cstring */
782782
{
783-
datalen+=MAXALIGN(strlen(DatumGetPointer(ptr))+1);
784-
ptr+=strlen(DatumGetPointer(ptr))+1;
783+
Sizeslen=strlen(DatumGetCString(ptr))+1;
784+
785+
datalen+=MAXALIGN(slen);
786+
ptr+=slen;
785787
}
786788
}
787789

@@ -830,7 +832,7 @@ range_deserialize(int maxvalues, SerializedRanges *serialized)
830832

831833
memcpy(dataptr,ptr,slen);
832834
dataptr+=MAXALIGN(slen);
833-
ptr+=(slen);
835+
ptr+=slen;
834836
}
835837

836838
/* make sure we haven't overflown the buffer end */
@@ -3032,19 +3034,17 @@ brin_minmax_multi_summary_out(PG_FUNCTION_ARGS)
30323034
idx=0;
30333035
for (i=0;i<ranges_deserialized->nranges;i++)
30343036
{
3035-
Datuma,
3036-
b;
3037+
char*a,
3038+
*b;
30373039
text*c;
30383040
StringInfoDatastr;
30393041

30403042
initStringInfo(&str);
30413043

3042-
a=FunctionCall1(&fmgrinfo,ranges_deserialized->values[idx++]);
3043-
b=FunctionCall1(&fmgrinfo,ranges_deserialized->values[idx++]);
3044+
a=OutputFunctionCall(&fmgrinfo,ranges_deserialized->values[idx++]);
3045+
b=OutputFunctionCall(&fmgrinfo,ranges_deserialized->values[idx++]);
30443046

3045-
appendStringInfo(&str,"%s ... %s",
3046-
DatumGetPointer(a),
3047-
DatumGetPointer(b));
3047+
appendStringInfo(&str,"%s ... %s",a,b);
30483048

30493049
c=cstring_to_text(str.data);
30503050

@@ -3084,7 +3084,7 @@ brin_minmax_multi_summary_out(PG_FUNCTION_ARGS)
30843084

30853085
a=FunctionCall1(&fmgrinfo,ranges_deserialized->values[idx++]);
30863086

3087-
appendStringInfoString(&str,DatumGetPointer(a));
3087+
appendStringInfoString(&str,DatumGetCString(a));
30883088

30893089
b=cstring_to_text(str.data);
30903090

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp