Skip to content

Commit a5ccef6

Browse files
committed
eliminate more trivial format strings ("%s", "...")
As a follow-up to commit 71d1d45, turn more trivial format strings (i.e. "%s" followed by a string literal) into just that string literal. - dump.c: String literals are more efficiently appended using sv_catpvs; C strings using sv_patv. No need to invoke the entire sv_catpvf machinery to parse a static "format string" of length 1. - malloc.c: Disentangle some warning messages and make them properly match their (previously orphaned) perldiag entries again. - os2/perlrexx.c: Turn sprintf(x, "...") into strcpy(x, "...").
1 parent 79ae12a commit a5ccef6

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed

dump.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -540,14 +540,14 @@ Perl_sv_peek(pTHX_ SV *sv)
540540
}
541541
}
542542
if (is_tmp || SvREFCNT(sv) > 1 || SvPADTMP(sv)) {
543-
sv_catpvf(t, "<");
543+
sv_catpvs(t, "<");
544544
if (SvREFCNT(sv) > 1)
545545
sv_catpvf(t, "%" UVuf, (UV)SvREFCNT(sv));
546546
if (SvPADTMP(sv))
547-
sv_catpvf(t, "%s", "P");
547+
sv_catpvs(t, "P");
548548
if (is_tmp)
549-
sv_catpvf(t, "%s", SvTEMP(t) ? "T" : "t");
550-
sv_catpvf(t, ">");
549+
sv_catpv(t, SvTEMP(t) ? "T" : "t");
550+
sv_catpvs(t, ">");
551551
}
552552
}
553553

malloc.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,7 +1704,7 @@ morecore(int bucket)
17041704
#endif
17051705
if (bucket == sizeof(MEM_SIZE)*8*BUCKETS_PER_POW2) {
17061706
MALLOC_UNLOCK;
1707-
croak2("%s", "Out of memory during ridiculously large request");
1707+
croak2("Out of memory during ridiculously large request");
17081708
}
17091709
if (bucket > max_bucket)
17101710
max_bucket = bucket;
@@ -1842,16 +1842,20 @@ Perl_mfree(Malloc_t where)
18421842
#ifdef RCHECK
18431843
{
18441844
dTHX;
1845-
if (!PERL_IS_ALIVE || !PL_curcop)
1846-
Perl_ck_warner_d(aTHX_ packWARN(WARN_MALLOC), "%s free() ignored (RMAGIC, PERL_CORE)",
1847-
ovp->ov_rmagic == RMAGIC - 1 ?
1848-
"Duplicate" : "Bad");
1845+
if (!PERL_IS_ALIVE || !PL_curcop) {
1846+
if (ovp->ov_rmagic == RMAGIC - 1)
1847+
Perl_ck_warner_d(aTHX_ packWARN(WARN_MALLOC),
1848+
"Duplicate free() ignored (%s)", "RMAGIC, PERL_CORE");
1849+
else
1850+
Perl_ck_warner_d(aTHX_ packWARN(WARN_MALLOC),
1851+
"Bad free() ignored (%s)", "RMAGIC, PERL_CORE");
1852+
}
18491853
}
18501854
#else
18511855
{
18521856
dTHX;
18531857
if (!PERL_IS_ALIVE || !PL_curcop)
1854-
Perl_ck_warner_d(aTHX_ packWARN(WARN_MALLOC), "%s", "Bad free() ignored (PERL_CORE)");
1858+
Perl_ck_warner_d(aTHX_ packWARN(WARN_MALLOC), "Bad free() ignored (%s)", "PERL_CORE");
18551859
}
18561860
#endif
18571861
return; /* sanity */
@@ -1947,18 +1951,18 @@ Perl_realloc(void *mp, size_t nbytes)
19471951
#ifdef RCHECK
19481952
{
19491953
dTHX;
1950-
if (!PERL_IS_ALIVE || !PL_curcop)
1951-
Perl_ck_warner_d(aTHX_ packWARN(WARN_MALLOC), "%srealloc() %signored",
1952-
(ovp->ov_rmagic == RMAGIC - 1 ? "" : "Bad "),
1953-
ovp->ov_rmagic == RMAGIC - 1
1954-
? "of freed memory " : "");
1954+
if (!PERL_IS_ALIVE || !PL_curcop) {
1955+
if (ovp->ov_rmagic == RMAGIC - 1)
1956+
Perl_ck_warner_d(aTHX_ packWARN(WARN_MALLOC), "realloc() of freed memory ignored");
1957+
else
1958+
Perl_ck_warner_d(aTHX_ packWARN(WARN_MALLOC), "Bad realloc() ignored");
1959+
}
19551960
}
19561961
#else
19571962
{
19581963
dTHX;
19591964
if (!PERL_IS_ALIVE || !PL_curcop)
1960-
Perl_ck_warner_d(aTHX_ packWARN(WARN_MALLOC), "%s",
1961-
"Bad realloc() ignored");
1965+
Perl_ck_warner_d(aTHX_ packWARN(WARN_MALLOC), "Bad realloc() ignored");
19621966
}
19631967
#endif
19641968
return NULL; /* sanity */

os2/perlrexx.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ ULONG PERL (PCSZ name, LONG rargc, const RXSTRING *rargv,
135135
ret = 1;
136136
else {
137137
ret = 0;
138-
sprintf(retstr->strptr, "%s", "ok");
138+
strcpy(retstr->strptr, "ok");
139139
retstr->strlength = strlen (retstr->strptr);
140140
}
141141
PERL_SYS_TERM1(0);
@@ -162,7 +162,7 @@ ULONG PERLTERM (PCSZ name, LONG rargc, const RXSTRING *rargv,
162162
perl_free(my_perl);
163163
my_perl = 0;
164164

165-
sprintf(retstr->strptr, "%s", "ok");
165+
strcpy(retstr->strptr, "ok");
166166
retstr->strlength = strlen (retstr->strptr);
167167
return 0;
168168
}
@@ -176,7 +176,7 @@ ULONG PERLINIT (PCSZ name, LONG rargc, const RXSTRING *rargv,
176176
if (!init_perl(1))
177177
return 1;
178178

179-
sprintf(retstr->strptr, "%s", "ok");
179+
strcpy(retstr->strptr, "ok");
180180
retstr->strlength = strlen (retstr->strptr);
181181
return 0;
182182
}

pod/perldiag.pod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ most likely an unexpected right brace '}'.
476476
symbol has no filehandle associated with it. Perhaps you didn't do an
477477
open(), or did it in another package.
478478

479-
=item Bad free() ignored
479+
=item Bad free() ignored (%s)
480480

481481
(S malloc) An internal routine called free() on something that had never
482482
been malloc()ed in the first place. Mandatory, but can be disabled by
@@ -2324,7 +2324,7 @@ See L<perlfunc/dump>.
23242324

23252325
(F) Your machine doesn't support dump/undump.
23262326

2327-
=item Duplicate free() ignored
2327+
=item Duplicate free() ignored (%s)
23282328

23292329
(S malloc) An internal routine called free() on something that had
23302330
already been freed.

t/porting/diag.t

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,15 +701,13 @@ setnetent not implemented!
701701
setprotoent not implemented!
702702
set %s %p %p %p
703703
setservent not implemented!
704-
%s free() ignored (RMAGIC, PERL_CORE)
705704
%s has too many errors.
706705
SIG%s handler "%s" not defined.
707706
%s in %s
708707
Size magic not implemented
709708
%s: name `%s' too long
710709
%s not implemented!
711710
%s number > %s non-portable
712-
%srealloc() %signored
713711
%s on %s %s
714712
%s: %s
715713
Starting Full Screen process with flag=%d, mytype=%d

0 commit comments

Comments
 (0)