Skip to content

Commit 7d63349

Browse files
committed
Remove all formatting from string
1 parent d02b0f5 commit 7d63349

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/lib.error.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ void vlogmsg(int msglevel, const char *mesg, va_list ap)
7878
struct tm tm_buf;
7979
char timestring[128];
8080
char *progname_escaped;
81+
char *progname_unformatted;
8182
char *buffer;
8283
int bufferlen;
8384
va_list aq;
@@ -112,10 +113,21 @@ void vlogmsg(int msglevel, const char *mesg, va_list ap)
112113
bufferlen = strlen(timestring)+strlen(progname_escaped)+strlen(mesg)+20;
113114
buffer = (char *)malloc(bufferlen);
114115
if ( buffer==NULL ) abort();
116+
progname_unformatted = (char *)malloc(1+strlen(progname_escaped));
117+
size_t str_tmp_pos, esc_tmp_pos;
118+
char ctmp;
119+
for(str_tmp_pos=0; str_tmp_pos<strlen(progname_escaped); str_tmp_pos++) {
120+
ctmp = progname_escaped[str_tmp_pos];
121+
if ( ctmp!='%' ) {
122+
progname_unformatted[esc_tmp_pos++] = ctmp;
123+
}
124+
}
125+
progname_unformatted[esc_tmp_pos] = 0;
115126

116127
snprintf(buffer, bufferlen, "[%s] %s[%d]: %s\n",
117-
timestring, progname_escaped, getpid(), mesg);
128+
timestring, progname_unformatted, getpid(), mesg);
118129

130+
free(progname_unformatted);
119131
free(progname_escaped);
120132

121133
if ( msglevel<=verbose ) {

0 commit comments

Comments
 (0)