Sync with libnet 1.16
[p5sagit/p5-mst-13.2.git] / sv.c
diff --git a/sv.c b/sv.c
index d6ae16c..4e6d930 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -5918,13 +5918,13 @@ Perl_sv_pos_b2u(pTHX_ register SV* sv, I32* offsetp)
            mg = mg_find(sv, PERL_MAGIC_utf8);
            if (mg && mg->mg_ptr) {
                cache = (STRLEN *) mg->mg_ptr;
-               if (cache[1] == *offsetp) {
+               if (cache[1] == (STRLEN)*offsetp) {
                     /* An exact match. */
                     *offsetp = cache[0];
 
                    return;
                }
-               else if (cache[1] < *offsetp) {
+               else if (cache[1] < (STRLEN)*offsetp) {
                    /* We already know part of the way. */
                    len = cache[0];
                    s  += cache[1];
@@ -5947,12 +5947,16 @@ Perl_sv_pos_b2u(pTHX_ register SV* sv, I32* offsetp)
 
                        while (backw--) {
                            p--;
-                           while (UTF8_IS_CONTINUATION(*p))
+                           while (UTF8_IS_CONTINUATION(*p)) {
                                p--;
+                               backw--;
+                           }
                            ubackw++;
                        }
 
                        cache[0] -= ubackw;
+                       *offsetp = cache[0];
+                       return;
                    }
                }
            }
@@ -9325,6 +9329,13 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV
             p = SvEND(sv);
             *p = '\0';
        }
+       /* 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",
+                       (PL_op->op_type == OP_PRTF) ? "" : "s");
        
        have = esignlen + zeros + elen;
        need = (have > width ? have : width);