Skip to content

Commit 71d1d45

Browse files
committed
turn croak("%s", "foo") into croak("foo")
There is no point in using a separate format string if the whole error message is written right next to it. Not only does this change lead to simpler code (passing one argument instead of two), it also exposes more error messages to t/porting/diag.t, which relies on croak's first argument to supply the message template. Also make an equivalent change to S_open_script, which passes a constant string in the form of an err variable that is not used anywhere else. (It used to be, but that code was deleted in commit 5bc7d00.)
1 parent a453807 commit 71d1d45

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

malloc.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ Perl_malloc(size_t nbytes)
12511251
BARK_64K_LIMIT("Allocation",nbytes,nbytes);
12521252
#ifdef DEBUGGING
12531253
if ((long)nbytes < 0)
1254-
croak("%s", "panic: malloc");
1254+
croak("panic: malloc");
12551255
#endif
12561256

12571257
bucket = adjust_size_and_find_bucket(&nbytes);
@@ -1817,7 +1817,7 @@ Perl_mfree(Malloc_t where)
18171817
return;
18181818
#ifdef DEBUGGING
18191819
if (PTR2UV(cp) & (MEM_ALIGNBYTES - 1))
1820-
croak("%s", "wrong alignment in free()");
1820+
croak("wrong alignment in free()");
18211821
#endif
18221822
ovp = (union overhead *)((caddr_t)cp
18231823
- sizeof (union overhead) * CHUNK_SHIFT);
@@ -1918,7 +1918,7 @@ Perl_realloc(void *mp, size_t nbytes)
19181918
MEM_SIZE size = nbytes;
19191919

19201920
if ((long)nbytes < 0)
1921-
croak("%s", "panic: realloc");
1921+
croak("panic: realloc");
19221922
#endif
19231923

19241924
BARK_64K_LIMIT("Reallocation",nbytes,size);

perl.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -4257,14 +4257,13 @@ S_open_script(pTHX_ const char *scriptname, bool dosearch, bool *suidscript)
42574257
char tmpname[sizeof(FAKE_BIT_BUCKET_TEMPLATE)] = {
42584258
FAKE_BIT_BUCKET_TEMPLATE
42594259
};
4260-
const char * const err = "Failed to create a fake bit bucket";
42614260
if (strEQ(scriptname, BIT_BUCKET)) {
42624261
int tmpfd = Perl_my_mkstemp_cloexec(tmpname);
42634262
if (tmpfd > -1) {
42644263
scriptname = tmpname;
42654264
close(tmpfd);
42664265
} else
4267-
Perl_croak(aTHX_ err);
4266+
Perl_croak(aTHX_ "Failed to create a fake bit bucket");
42684267
}
42694268
#endif
42704269
rsfp = PerlIO_open(scriptname,PERL_SCRIPT_MODE);

pod/perldiag.pod

+14
Original file line numberDiff line numberDiff line change
@@ -2588,6 +2588,11 @@ queue of such routines has been prematurely ended.
25882588
(F) Closing an output file from in-place editing, as with the C<-i>
25892589
command-line switch, failed.
25902590

2591+
=item Failed to create a fake bit bucket
2592+
2593+
(F) You tried to call perl with the B<-e> switch, but you're on a Cray system
2594+
and perl's F</dev/null> emulation was unable to create an empty temporary file.
2595+
25912596
=item False [] range "%s" in regex; marked by S<<-- HERE> in m/%s/
25922597

25932598
(W regexp)(F) A character class range must start and end at a literal
@@ -4932,6 +4937,11 @@ remaining memory (or virtual memory) to satisfy the request. However,
49324937
the request was judged large enough (compile-time default is 64K), so a
49334938
possibility to shut down by trapping this error is granted.
49344939

4940+
=item Out of memory during pack()
4941+
4942+
(F) An attempt was made to extend a string beyond the largest possible memory
4943+
allocation.
4944+
49354945
=item Out of memory during request for %s
49364946

49374947
(X)(F) The malloc() function returned 0, indicating there was
@@ -8294,6 +8304,10 @@ Warning is given and the operation is not done.
82948304
(W closed) The filehandle you're writing to got itself closed sometime
82958305
before now. Check your control flow.
82968306

8307+
=item wrong alignment in free()
8308+
8309+
(P) An invalid pointer was passed to C<Perl_mfree> (also known as C<Safefree>).
8310+
82978311
=item %s "\x%X" does not map to Unicode
82988312

82998313
(S utf8) When reading in different encodings, Perl tries to

pp.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -1847,7 +1847,8 @@ PP_wrapped(pp_repeat,
18471847
SSize_t max;
18481848

18491849
if ( items > SSize_t_MAX / (SSize_t)sizeof(SV *) / count )
1850-
Perl_croak(aTHX_ "%s","Out of memory during list extend");
1850+
/* diag_listed_as: Out of memory during %s extend */
1851+
Perl_croak(aTHX_ "Out of memory during list extend");
18511852
max = items * count;
18521853
MEXTEND(MARK, max);
18531854

@@ -1885,8 +1886,8 @@ PP_wrapped(pp_repeat,
18851886

18861887
if ( len > (MEM_SIZE_MAX-1) / (UV)count /* max would overflow */
18871888
)
1888-
Perl_croak(aTHX_ "%s",
1889-
"Out of memory during string extend");
1889+
/* diag_listed_as: Out of memory during %s extend */
1890+
Perl_croak(aTHX_ "Out of memory during string extend");
18901891
max = (UV)count * len + 1;
18911892
SvGROW(TARG, max);
18921893

pp_pack.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -361,14 +361,14 @@ STMT_START { \
361361
#define SAFE_UTF8_EXPAND(var) \
362362
STMT_START { \
363363
if ((var) > SSize_t_MAX / UTF8_EXPAND) \
364-
Perl_croak(aTHX_ "%s", "Out of memory during pack()"); \
364+
Perl_croak(aTHX_ "Out of memory during pack()"); \
365365
(var) = (var) * UTF8_EXPAND; \
366366
} STMT_END
367367

368368
#define GROWING2(utf8, cat, start, cur, item_size, item_count) \
369369
STMT_START { \
370370
if (SSize_t_MAX / (item_size) < (item_count)) \
371-
Perl_croak(aTHX_ "%s", "Out of memory during pack()"); \
371+
Perl_croak(aTHX_ "Out of memory during pack()"); \
372372
GROWING((utf8), (cat), (start), (cur), (item_size) * (item_count)); \
373373
} STMT_END
374374

@@ -378,7 +378,7 @@ STMT_START { \
378378
STRLEN catcur = (STRLEN)((cur) - (start)); \
379379
if (utf8) SAFE_UTF8_EXPAND(glen); \
380380
if (SSize_t_MAX - glen < catcur) \
381-
Perl_croak(aTHX_ "%s", "Out of memory during pack()"); \
381+
Perl_croak(aTHX_ "Out of memory during pack()"); \
382382
if (catcur + glen >= SvLEN(cat)) { \
383383
(start) = sv_exp_grow(cat, glen); \
384384
(cur) = (start) + SvCUR(cat); \

0 commit comments

Comments
 (0)