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

Commit08a46ad

Browse files
committed
Fix some more boundary-case errors in psql variable substitution:
wasn't really right for case where :var is at the end of the line,was definitely not right if var expanded to empty in that case,and failed to recalculate thislen before jumping back to rescan.
1 parentc3c54a2 commit08a46ad

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

‎src/bin/psql/mainloop.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.48 2002/06/15 19:37:48 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.49 2002/07/03 16:47:46 tgl Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"mainloop.h"
@@ -366,41 +366,46 @@ MainLoop(FILE *source)
366366
* temporarily overwritten */
367367

368368
in_length=strspn(&line[i+thislen],VALID_VARIABLE_CHARS);
369+
/* mark off the possible variable name */
369370
after=line[i+thislen+in_length];
370371
line[i+thislen+in_length]='\0';
371372

372-
/*
373-
* if the variable doesn't exist we'll leave the string as
374-
* is
375-
*/
376373
value=GetVariable(pset.vars,&line[i+thislen]);
374+
375+
/* restore overwritten character */
376+
line[i+thislen+in_length]=after;
377+
377378
if (value)
378379
{
380+
/* It is a variable, perform substitution */
379381
out_length=strlen(value);
380382

381-
/* Allow for 'after' character also 2002-05-27 */
382-
new=malloc(len+out_length- (1+in_length)+1+1);
383+
new=malloc(len+out_length-in_length+1);
383384
if (!new)
384385
{
385386
psql_error("out of memory\n");
386387
exit(EXIT_FAILURE);
387388
}
388389

389-
sprintf(new,"%.*s%s%c",i,line,value,after);
390-
if (after)
391-
strcat(new,line+i+1+in_length+1);
390+
sprintf(new,"%.*s%s%s",i,line,value,
391+
&line[i+thislen+in_length]);
392392

393393
free(line);
394394
line=new;
395395
len=strlen(new);
396396

397-
gotorescan;/* reparse the just substituted */
397+
if (i<len)
398+
{
399+
thislen=PQmblen(line+i,pset.encoding);
400+
gotorescan;/* reparse the just substituted */
401+
}
398402
}
399403
else
400404
{
401-
/* restore overwritten character */
402-
line[i+thislen+in_length]=after;
403-
/* move on ... */
405+
/*
406+
* if the variable doesn't exist we'll leave the string as
407+
* is ... move on ...
408+
*/
404409
}
405410
}
406411

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp