Use StringInfo when logging distributed snapshot info
Under GCC 8, I get a warning (and rumor has it that you get this under GCC 7 with `-Wrestrict`): ``` sharedsnapshot.c: In function ‘LogDistributedSnapshotInfo’: sharedsnapshot.c:924:11: warning: passing argument 1 to restrict-qualified parameter aliases with argument 4 [-Wrestrict] snprintf(message, MESSAGE_LEN, "%s, In progress array: {", ^~~~~~~ message); ~~~~~~~ sharedsnapshot.c:930:13: warning: passing argument 1 to restrict-qualified parameter aliases with argument 4 [-Wrestrict] snprintf(message, MESSAGE_LEN, "%s, (dx%d)", ^~~~~~~ message, ds->inProgressXidArray[no]); ~~~~~~~ sharedsnapshot.c:933:13: warning: passing argument 1 to restrict-qualified parameter aliases with argument 4 [-Wrestrict] snprintf(message, MESSAGE_LEN, "%s (dx%d)", ^~~~~~~ message, ds->inProgressXidArray[no]); ~~~~~~~ ``` Upon further inspection, the compiler is right: according to C99, it is undefined behavior to pass aliased arguments to the "str" argument of `snprint` (`restrict`-qualified function parameters, to be pedantic). To make this safer and more readable, this patch switches to using the StringInfo API. This change might come with a teeny tiny bit of performance because of: 1. stack vs heap allocation 2. larger initial allocation size of StringInfo But this area of the code is *never* a hot spot, and `appendStringInfo` and friends are arguably faster than our old call patterns of `snprintf`, so I won't sweat on that. (cherry picked from commit 89553ad2) (Back port of greenplum-db/gpdb#5753)
Showing
想要评论请 注册 或 登录