summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Holland-Moritz <mhx-perl@gmx.net>2003-06-15 12:48:40 +0200
committerJarkko Hietaniemi <jhi@iki.fi>2003-06-15 07:41:23 +0000
commit94330da298089e668ae1ded0e8f984462f3f70b3 (patch)
treed924f6cd728f10c602b8249e6f38e8f53a77cb46
parent8bdbb4723ae10faa8f5ebfec78d78879f0c6b8e1 (diff)
downloadperl-94330da298089e668ae1ded0e8f984462f3f70b3.tar.gz
Re: [PATCH: sv.c] strchr() running amok in sv_vcatpvfn()
From: "Marcus Holland-Moritz" <mhx-perl@gmx.net> Message-ID: <004a01c3331a$ec001320$3445eed9@R2D2> p4raw-id: //depot/perl@19786
-rw-r--r--embed.fnc1
-rw-r--r--embed.h6
-rw-r--r--proto.h1
-rw-r--r--sv.c27
4 files changed, 3 insertions, 32 deletions
diff --git a/embed.fnc b/embed.fnc
index b3efd6e3d4..be08619186 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -1236,7 +1236,6 @@ s |bool |utf8_mg_pos_init |SV *sv|MAGIC **mgp|STRLEN **cachep|I32 i|I32 *offsetp
sM |void |sv_release_COW |SV *sv|char *pvx|STRLEN cur|STRLEN len \
|U32 hash|SV *after
#endif
-sn |const char*|my_strnchr |const char* |int c |size_t
#endif
#if defined(PERL_IN_TOKE_C) || defined(PERL_DECL_PROT)
diff --git a/embed.h b/embed.h
index cbef935267..5907e20af5 100644
--- a/embed.h
+++ b/embed.h
@@ -1886,9 +1886,6 @@
#define sv_release_COW S_sv_release_COW
#endif
#endif
-#ifdef PERL_CORE
-#define my_strnchr S_my_strnchr
-#endif
#endif
#if defined(PERL_IN_TOKE_C) || defined(PERL_DECL_PROT)
#ifdef PERL_CORE
@@ -4360,9 +4357,6 @@
#define sv_release_COW(a,b,c,d,e,f) S_sv_release_COW(aTHX_ a,b,c,d,e,f)
#endif
#endif
-#ifdef PERL_CORE
-#define my_strnchr S_my_strnchr
-#endif
#endif
#if defined(PERL_IN_TOKE_C) || defined(PERL_DECL_PROT)
#ifdef PERL_CORE
diff --git a/proto.h b/proto.h
index 880e269ab0..1f03b3bdaa 100644
--- a/proto.h
+++ b/proto.h
@@ -1186,7 +1186,6 @@ STATIC bool S_utf8_mg_pos_init(pTHX_ SV *sv, MAGIC **mgp, STRLEN **cachep, I32 i
#if defined(PERL_COPY_ON_WRITE)
STATIC void S_sv_release_COW(pTHX_ SV *sv, char *pvx, STRLEN cur, STRLEN len, U32 hash, SV *after);
#endif
-STATIC const char* S_my_strnchr(const char*, int c, size_t);
#endif
#if defined(PERL_IN_TOKE_C) || defined(PERL_DECL_PROT)
diff --git a/sv.c b/sv.c
index 9d6948e948..4e6d930ed2 100644
--- a/sv.c
+++ b/sv.c
@@ -8431,25 +8431,6 @@ Perl_sv_vsetpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV
sv_vcatpvfn(sv, pat, patlen, args, svargs, svmax, maybe_tainted);
}
-/* my_strnchr(): private function for use in sv_vcatpvfn()
- *
- * Like strchr(), but allows to use strings that are not null-terminated.
- * The string length must be given instead and it _must_ be correct, as
- * the function does not stop searching when a '\0' is discovered.
- * This would also allow to explicitly search for '\0' characters.
- */
-
-STATIC
-const char *
-S_my_strnchr(const char* s, int c, size_t n)
-{
- if (s)
- for (; n > 0; n--, s++)
- if ((int)*s == c)
- return s;
- return NULL;
-}
-
/* private function for use in sv_vcatpvfn via the EXPECT_NUMBER macro */
STATIC I32
@@ -9348,11 +9329,9 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV
p = SvEND(sv);
*p = '\0';
}
- /* Don't use strchr() here, because eptr does not necessarily point */
- /* to a null-terminated string. E.g. with the format "%-10c", eptr */
- /* points to c (a single char on the stack), which makes strchr() */
- /* run amok over the stack until it eventually hits '\n' or '\0'. */
- if (left && ckWARN(WARN_PRINTF) && my_strnchr(eptr, '\n', elen) &&
+ /* Use memchr() instead of strchr(), as eptr is not guaranteed */
+ /* to point to a null-terminated string. */
+ if (left && ckWARN(WARN_PRINTF) && memchr(eptr, '\n', elen) &&
(PL_op->op_type == OP_PRTF || PL_op->op_type == OP_SPRINTF))
Perl_warner(aTHX_ packWARN(WARN_PRINTF),
"Newline in left-justified string for %sprintf",