summaryrefslogtreecommitdiff
path: root/contrib/intarray/_int.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2002-09-02 06:11:43 +0000
committerBruce Momjian <bruce@momjian.us>2002-09-02 06:11:43 +0000
commita12b4e279bc12a7cd7b7d679fcac4689ac4aba7b (patch)
treeff120ff0c156829d771bdc874fe8fbb2aa4fbf6e /contrib/intarray/_int.c
parent48e1a39924d9e0674306156a6519cf5688c67c43 (diff)
I checked all the previous string handling errors and most of them were
already fixed by You. However there were a few left and attached patch should fix the rest of them. I used StringInfo only in 2 places and both of them are inside debug ifdefs. Only performance penalty will come from using strlen() like all the other code does. I also modified some of the already patched parts by changing snprintf(buf, 2 * BUFSIZE, ... style lines to snprintf(buf, sizeof(buf), ... where buf is an array. Jukka Holappa
Diffstat (limited to 'contrib/intarray/_int.c')
-rw-r--r--contrib/intarray/_int.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/contrib/intarray/_int.c b/contrib/intarray/_int.c
index 1c0de0bce80..75ebf5d8dda 100644
--- a/contrib/intarray/_int.c
+++ b/contrib/intarray/_int.c
@@ -22,6 +22,7 @@
#include "utils/array.h"
#include "utils/builtins.h"
#include "storage/bufpage.h"
+#include "lib/stringinfo.h"
/* number ranges for compression */
#define MAXNUMRANGE 100
@@ -99,20 +100,19 @@ typedef char *BITVECP;
static void
printarr(ArrayType *a, int num)
{
- char bbb[16384];
+ StringInfoData bbb;
char *cur;
int l;
int *d;
d = ARRPTR(a);
- *bbb = '\0';
- cur = bbb;
+ initStringInfo(&bbb);
for (l = 0; l < min(num, ARRNELEMS(a)); l++)
{
- sprintf(cur, "%d ", d[l]);
- cur = strchr(cur, '\0');
+ appendStringInfo(&bbb, "%d ", d[l]);
}
- elog(DEBUG3, "\t\t%s", bbb);
+ elog(DEBUG3, "\t\t%s", bbb.data);
+ pfree(bbb.data);
}
static void
printbitvec(BITVEC bv)
@@ -1924,7 +1924,7 @@ bqarr_in(PG_FUNCTION_ARGS) {
NODE *tmp;
int4 pos=0;
#ifdef BS_DEBUG
- char pbuf[16384],*cur;
+ StringInfoData pbuf;
#endif
state.buf = buf;
@@ -1955,16 +1955,15 @@ bqarr_in(PG_FUNCTION_ARGS) {
pos = query->size-1;
findoprnd( ptr, &pos );
#ifdef BS_DEBUG
- cur = pbuf;
- *cur = '\0';
+ initStringInfo(&pbuf);
for( i=0;i<query->size;i++ ) {
if ( ptr[i].type == OPR )
- sprintf(cur, "%c(%d) ", ptr[i].val, ptr[i].left);
+ appendStringInfo(&pbuf, "%c(%d) ", ptr[i].val, ptr[i].left);
else
- sprintf(cur, "%d ", ptr[i].val );
- cur = strchr(cur,'\0');
+ appendStringInfo(&pbuf, "%d ", ptr[i].val );
}
- elog(DEBUG3,"POR: %s", pbuf);
+ elog(DEBUG3,"POR: %s", pbuf.data);
+ pfree(pbuf.data);
#endif
PG_RETURN_POINTER( query );