From: Steve Peters Date: Mon, 10 Jul 2006 13:55:39 +0000 (+0000) Subject: Change existing uses of strlcpy()/strlcat() to use new my_strlcpy()/ X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=28f0d0ec424c9050a6c7d38541d2e6b5e66fb97c;p=p5sagit%2Fp5-mst-13.2.git Change existing uses of strlcpy()/strlcat() to use new my_strlcpy()/ my_strlcat() API. Convert ext/File/Glob/bsd_glob.c to use my_strlcat(). Add to the strlcy()/strlcat() todo entry. p4raw-id: //depot/perl@28528 --- diff --git a/doio.c b/doio.c index 8a04766..1fcb165 100644 --- a/doio.c +++ b/doio.c @@ -258,17 +258,10 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, } mode[0] = 'w'; writing = 1; -#ifdef HAS_STRLCAT if (out_raw) - strlcat(mode, "b", PERL_MODE_MAX - 1); + my_strlcat(mode, "b", PERL_MODE_MAX - 1); else if (out_crlf) - strlcat(mode, "t", PERL_MODE_MAX - 1); -#else - if (out_raw) - strcat(mode, "b"); - else if (out_crlf) - strcat(mode, "t"); -#endif + my_strlcat(mode, "t", PERL_MODE_MAX - 1); if (num_svs > 1) { fp = PerlProc_popen_list(mode, num_svs, svp); } @@ -296,17 +289,10 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, } writing = 1; -#ifdef HAS_STRLCAT if (out_raw) - strlcat(mode, "b", PERL_MODE_MAX - 1); + my_strlcat(mode, "b", PERL_MODE_MAX - 1); else if (out_crlf) - strlcat(mode, "t", PERL_MODE_MAX - 1); -#else - if (out_raw) - strcat(mode, "b"); - else if (out_crlf) - strcat(mode, "t"); -#endif + my_strlcat(mode, "t", PERL_MODE_MAX - 1); if (*type == '&') { duplicity: dodup = PERLIO_DUP_FD; @@ -429,17 +415,10 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, type++; } while (isSPACE(*type)); mode[0] = 'r'; -#ifdef HAS_STRLCAT if (in_raw) - strlcat(mode, "b", PERL_MODE_MAX - 1); + my_strlcat(mode, "b", PERL_MODE_MAX - 1); else if (in_crlf) - strlcat(mode, "t", PERL_MODE_MAX - 1); -#else - if (in_raw) - strcat(mode, "b"); - else if (in_crlf) - strcat(mode, "t"); -#endif + my_strlcat(mode, "t", PERL_MODE_MAX - 1); if (*type == '&') { goto duplicity; } @@ -490,17 +469,10 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, TAINT_PROPER("piped open"); mode[0] = 'r'; -#ifdef HAS_STRLCAT if (in_raw) - strlcat(mode, "b", PERL_MODE_MAX - 1); + my_strlcat(mode, "b", PERL_MODE_MAX - 1); else if (in_crlf) - strlcat(mode, "t", PERL_MODE_MAX - 1); -#else - if (in_raw) - strcat(mode, "b"); - else if (in_crlf) - strcat(mode, "t"); -#endif + my_strlcat(mode, "t", PERL_MODE_MAX - 1); if (num_svs > 1) { fp = PerlProc_popen_list(mode,num_svs,svp); @@ -528,17 +500,10 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, ; mode[0] = 'r'; -#ifdef HAS_STRLCAT if (in_raw) - strlcat(mode, "b", PERL_MODE_MAX - 1); + my_strlcat(mode, "b", PERL_MODE_MAX - 1); else if (in_crlf) - strlcat(mode, "t", PERL_MODE_MAX - 1); -#else - if (in_raw) - strcat(mode, "b"); - else if (in_crlf) - strcat(mode, "t"); -#endif + my_strlcat(mode, "t", PERL_MODE_MAX - 1); if (*name == '-' && name[1] == '\0') { fp = PerlIO_stdin(); @@ -1493,19 +1458,11 @@ Perl_do_exec3(pTHX_ const char *incmd, int fd, int do_report) char flags[PERL_FLAGS_MAX]; if (strnEQ(cmd,PL_cshname,PL_cshlen) && strnEQ(cmd+PL_cshlen," -c",3)) { -#ifdef HAS_STRLCPY - strlcpy(flags, "-c", PERL_FLAGS_MAX); -#else - strcpy(flags,"-c"); -#endif + my_strlcpy(flags, "-c", PERL_FLAGS_MAX); s = cmd+PL_cshlen+3; if (*s == 'f') { s++; -#ifdef HAS_STRLCPY - strlcat(flags, "f", PERL_FLAGS_MAX - 2); -#else - strcat(flags,"f"); -#endif + my_strlcat(flags, "f", PERL_FLAGS_MAX - 2); } if (*s == ' ') s++; @@ -2317,7 +2274,7 @@ Perl_do_shmio(pTHX_ I32 optype, SV **mark, SV **sp) STRLEN len; const char *mbuf = SvPV_const(mstr, len); - const I32 n = ((I32)len > msize) ? msize : (I32)len; + const I32 n = (len > msize) ? msize : len; Copy(mbuf, shm + mpos, n, char); if (n < msize) memzero(shm + mpos + n, msize - n); diff --git a/ext/File/Glob/bsd_glob.c b/ext/File/Glob/bsd_glob.c index 78a8c64..c1dbd2c 100644 --- a/ext/File/Glob/bsd_glob.c +++ b/ext/File/Glob/bsd_glob.c @@ -1131,9 +1131,9 @@ g_opendir(register Char *str, glob_t *pglob) if (!*str) { #ifdef MACOS_TRADITIONAL - strcpy(buf, ":"); + my_strlcpy(buf, ":", sizeof(buf)); #else - strcpy(buf, "."); + my_strlcpy(buf, ".", sizeof(buf)); #endif } else { if (g_Ctoc(str, buf, sizeof(buf))) diff --git a/pod/perltodo.pod b/pod/perltodo.pod index bade067..9ffb628 100644 --- a/pod/perltodo.pod +++ b/pod/perltodo.pod @@ -622,7 +622,9 @@ source filters. All this could be fixed. =head2 Integrate Russ Allbery's strlcat/strlcpy implementation -And remove the last remaining uses of strcat() and strcpy(). +And remove the last remaining uses of strcat() and strcpy(). Also, add +my_strlcat() and my_strlcpy() to Devel::PPPort so previous versions of Perl can +use these APIs. =head1 Big projects diff --git a/pp_ctl.c b/pp_ctl.c index 929f5a2..1f9fa4a 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -3423,9 +3423,7 @@ PP(pp_entereval) U32 seq; HV *saved_hh = NULL; const char * const fakestr = "_<(eval )"; -#ifdef HAS_STRLCPY const int fakelen = 9 + 1; -#endif if (PL_op->op_private & OPpEVAL_HAS_HH) { saved_hh = (HV*) SvREFCNT_inc(POPs); @@ -3498,11 +3496,7 @@ PP(pp_entereval) if (PERLDB_INTER && was != (I32)PL_sub_generation /* Some subs defined here. */ && ret != PL_op->op_next) { /* Successive compilation. */ /* Copy in anything fake and short. */ -#ifdef HAS_STRLCPY - strlcpy(safestr, fakestr, fakelen); -#else - strcpy(safestr, fakestr); -#endif /* #ifdef HAS_STRLCPY */ + my_strlcpy(safestr, fakestr, fakelen); } return DOCATCH(ret); } diff --git a/util.c b/util.c index 6e291d3..7a3be16 100644 --- a/util.c +++ b/util.c @@ -3118,13 +3118,7 @@ Perl_find_script(pTHX_ const char *scriptname, bool dosearch, if (len == 2 && tmpbuf[0] == '.') seen_dot = 1; #endif -#ifdef HAS_STRLCAT - (void)strlcpy(tmpbuf + len, scriptname, sizeof(tmpbuf) - len); -#else - /* FIXME? Convert to memcpy by storing previous strlen(scriptname) - */ - (void)strcpy(tmpbuf + len, scriptname); -#endif /* #ifdef HAS_STRLCAT */ + (void)my_strlcpy(tmpbuf + len, scriptname, sizeof(tmpbuf) - len); #endif /* !VMS */ #ifdef SEARCH_EXTS