Skip Menu |
 

This queue is for tickets about the String-Strip CPAN distribution.

Report information
The Basics
Id: 70028
Status: resolved
Priority: 0/
Queue: String-Strip

People
Owner: Nobody in particular
Requestors: RWSTAUNER [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 1.01
Fixed in: (no value)



Subject: String gets mangled with 8 or more characters on 64bit machine
Download (untitled) / with headers
text/plain 702b
At least I think that's the problem: perl -C -MString::Strip=StripLTSpace -e '@t = ("Foo Bar", "Foo Bar1", "1234567", "12345678"); printf "1..%d\n", scalar @t; foreach (@t){ $s = " $_ "; StripLTSpace($s); print "not " unless $s eq $_; print "ok 1 # [$e] == [$s]\n"; }' 1..4 ok 1 # [] == [Foo Bar] not ok 1 # [] == [Foo Br11] ok 1 # [] == [1234567] not ok 1 # [] == [12345788] Considering 8 characters is the magic number I'm guessing it's a 64bit problem (though I admit I know little about it). I get the same results on 5.8.8, 5.10.1, 5.12.3, 5.14.1, installed via perlbrew or the system binary on Xubuntu 11.04. Also it appears that some of the tests fail but it installs anyway (see attached).
Subject: string-strip-perl-v.txt
Summary of my perl5 (revision 5 version 14 subversion 1) configuration: Platform: osname=linux, osvers=2.6.38-10-generic, archname=x86_64-linux uname='linux raptor 2.6.38-10-generic #46-ubuntu smp tue jun 28 15:07:17 utc 2011 x86_64 x86_64 x86_64 gnulinux ' config_args='-de -Dprefix=/home/rando/perl5/perlbrew/perls/perl-5.14.1' hint=recommended, useposix=true, d_sigaction=define useithreads=undef, usemultiplicity=undef useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef use64bitint=define, use64bitall=define, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2', cppflags='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include' ccversion='', gccversion='4.5.2', gccosandvers='' intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16 ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='cc', ldflags =' -fstack-protector -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib /usr/lib/x86_64-linux-gnu /lib64 /usr/lib64 libs=-lnsl -ldl -lm -lcrypt -lutil -lc perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc libc=, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='2.13' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector' Characteristics of this binary (from libperl): Compile-time options: PERL_DONT_CREATE_GVSV PERL_MALLOC_WRAP PERL_PRESERVE_IVUV USE_64_BIT_ALL USE_64_BIT_INT USE_LARGE_FILES USE_PERLIO USE_PERL_ATOF Built under linux Compiled at Jul 25 2011 12:26:25 %ENV: PERL5LIB="/home/rando/perl5-autolookout/lib/perl5/x86_64-linux:/home/rando/perl5-autolookout/lib/perl5" PERLBREW_HOME="/home/rando/.perlbrew" PERLBREW_PATH="/home/rando/perl5/perlbrew/bin:/home/rando/perl5/perlbrew/perls/perl-5.14.1/bin" PERLBREW_PERL="perl-5.14.1" PERLBREW_ROOT="/home/rando/perl5/perlbrew" PERLBREW_VERSION="0.27" PERL_CPANM_OPT="--save-dists /home/rando/perl5/cpan/mini --mirror http://localhost:4999/CPAN/ --mirror http://cpan.ezarticleinformation.com/ --mirror http://search.cpan.org/CPAN/" @INC: /home/rando/perl5-autolookout/lib/perl5/x86_64-linux /home/rando/perl5-autolookout/lib/perl5 /home/rando/perl5/perlbrew/perls/perl-5.14.1/lib/site_perl/5.14.1/x86_64-linux /home/rando/perl5/perlbrew/perls/perl-5.14.1/lib/site_perl/5.14.1 /home/rando/perl5/perlbrew/perls/perl-5.14.1/lib/5.14.1/x86_64-linux /home/rando/perl5/perlbrew/perls/perl-5.14.1/lib/5.14.1 .
Subject: string-strip-installation.txt
String-Strip-1.01/ String-Strip-1.01/Makefile.PL String-Strip-1.01/Changes String-Strip-1.01/test.pl String-Strip-1.01/Strip.xs String-Strip-1.01/Strip.pm String-Strip-1.01/README String-Strip-1.01/MANIFEST CPAN: File::Temp loaded ok (v0.22) Package came without SIGNATURE CPAN: CPAN::Meta loaded ok (v2.110930001) CPAN.pm: Going to build B/BP/BPOWERS/String-Strip-1.01.tar.gz CPAN: CPAN::Reporter loaded ok (v1.1902) Checking if your kit is complete... Looks good Writing Makefile for String::Strip Writing MYMETA.yml and MYMETA.json (/home/rando/perl5/perlbrew/perls/perl-5.8.8/bin/perl Makefile.PL INSTALLDIRS=site exited with 0) CPAN::Reporter: Makefile.PL result is 'pass', No errors. CPAN: Module::CoreList loaded ok (v2.54) cp Strip.pm blib/lib/String/Strip.pm AutoSplitting blib/lib/String/Strip.pm (blib/lib/auto/String/Strip) /home/rando/perl5/perlbrew/perls/perl-5.8.8/bin/perl /home/rando/perl5/perlbrew/perls/perl-5.8.8/lib/site_perl/5.8.8/ExtUtils/xsubpp -typemap /home/rando/perl5/perlbrew/perls/perl-5.8.8/lib/5.8.8/ExtUtils/typemap Strip.xs > Strip.xsc && mv Strip.xsc Strip.c cc -c -fno-strict-aliasing -pipe -Wdeclaration-after-statement -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -DVERSION=\"1.01\" -DXS_VERSION=\"1.01\" -fpic "-I/home/rando/perl5/perlbrew/perls/perl-5.8.8/lib/5.8.8/x86_64-linux/CORE" Strip.c Running Mkbootstrap for String::Strip () chmod 644 Strip.bs rm -f blib/arch/auto/String/Strip/Strip.so cc -shared -L/usr/local/lib Strip.o -o blib/arch/auto/String/Strip/Strip.so \ \ chmod 755 blib/arch/auto/String/Strip/Strip.so cp Strip.bs blib/arch/auto/String/Strip/Strip.bs chmod 644 blib/arch/auto/String/Strip/Strip.bs Manifying blib/man3/String::Strip.3 (/usr/bin/make exited with 0) CPAN::Reporter: make result is 'pass', No errors. BPOWERS/String-Strip-1.01.tar.gz /usr/bin/make -- OK CPAN: YAML::XS loaded ok (v0.35) Running make test PERL_DL_NONLAZY=1 /home/rando/perl5/perlbrew/perls/perl-5.8.8/bin/perl "-Iblib/lib" "-Iblib/arch" test.pl 1..42 ok 1 ok 2 ok 3 ok 4 ok 5 ok 6 ok 7 ok 8 ok 9 ok 10 ok 11 ok 12 ok 13 ok 14 ok 15 ok 16 ok 17 not ok 18 not ok 19 ok 20 ok 21 ok 22 ok 23 ok 24 ok 25 ok 26 ok 27 ok 28 ok 29 ok 30 ok 31 ok 32 ok 33 ok 34 ok 35 ok 36 not ok 37 ok 38 ok 39 ok 40 ok 41 ok 42 (/usr/bin/make test exited with 0) CPAN::Reporter: Test result is 'pass', 'make test' no errors. CPAN::Reporter: preparing a CPAN Testers report for String-Strip-1.01 CPAN::Reporter: sending test report with 'pass' via Metabase BPOWERS/String-Strip-1.01.tar.gz /usr/bin/make test -- OK Running make install Prepending /home/rando/.cpan/build/String-Strip-1.01-_cmfyz/blib/arch /home/rando/.cpan/build/String-Strip-1.01-_cmfyz/blib/lib to PERL5LIB for 'install' Files found in blib/arch: installing files in blib/lib into architecture dependent library tree Installing /home/rando/perl5/perlbrew/perls/perl-5.8.8/lib/site_perl/5.8.8/x86_64-linux/auto/String/Strip/Strip.so Installing /home/rando/perl5/perlbrew/perls/perl-5.8.8/lib/site_perl/5.8.8/x86_64-linux/auto/String/Strip/Strip.bs Installing /home/rando/perl5/perlbrew/perls/perl-5.8.8/lib/site_perl/5.8.8/x86_64-linux/auto/String/Strip/autosplit.ix Installing /home/rando/perl5/perlbrew/perls/perl-5.8.8/lib/site_perl/5.8.8/x86_64-linux/String/Strip.pm Installing /home/rando/perl5/perlbrew/perls/perl-5.8.8/man/man3/String::Strip.3 Appending installation info to /home/rando/perl5/perlbrew/perls/perl-5.8.8/lib/5.8.8/x86_64-linux/perllocal.pod BPOWERS/String-Strip-1.01.tar.gz /usr/bin/make install UNINST=1 -- OK
Download (untitled) / with headers
text/plain 506b
realized there was a goof in my previous perl code. The problem was still evident, but here it is the code using the correct variable: perl -C -MString::Strip=StripLTSpace -e '@t = ("Foo Bar", "Foo Bar1", "1234567", "12345678"); printf "1..%d\n", scalar @t; foreach (@t){ $s = " $_ "; StripLTSpace($s); print "not " unless $s eq $_; print "ok 1 # [$_] => [$s]\n"; }' 1..4 ok 1 # [Foo Bar] => [Foo Bar] not ok 1 # [Foo Bar1] => [Foo Br11] ok 1 # [1234567] => [1234567] not ok 1 # [12345678] => [12345788]
Download (untitled) / with headers
text/plain 434b
To chuck in 2 cents worth, I notice the leading strippers use an strcpy() to move the remaining chars down. I think the c99 spec is that strcpy() is unspecified if source and destination overlap. Dunno if that causes the bug, but may be worth avoiding. (For in-place stripping of leading chars maybe sv_chop() without copying. Dunno how well it works in practice or if handles magic. Maybe SvCUR_set() for trimming the end too.)
From: chrishammond [...] ymail.com
Download (untitled) / with headers
text/plain 861b
Noticed this failing on RHEL6, too - strcpy() behaviour is undefined where the source and destination strings overlap, memmove() is safer to use: +++ String-Strip-1.01/Strip.xs 2011-11-23 10:42:01.000000000 -0500 @@ -38,15 +38,16 @@ char *arg CODE: char *pcF, *pcR; + int i; if (!SvOK(ST(0))) XSRETURN_UNDEF; - if (strlen(arg)) { + if (i = strlen(arg)) { for (pcF = arg; *pcF && isspace(*pcF); pcF++) ; - strcpy(arg, pcF); + memmove(arg, pcF, i); } OUTPUT: arg @@ -56,6 +57,7 @@ char *arg CODE: char *pcF, *pcR; + char *pcTemp = strdup(arg); int i; if (!SvOK(ST(0))) @@ -70,7 +72,7 @@ for (pcF = arg; *pcF && isspace(*pcF); pcF++) ; - strcpy(arg, pcF); + memmove(arg, pcF, i); } } OUTPUT:
From: chrishammond [...] ymail.com
Actually, ignore this line, not required. + char *pcTemp = strdup(arg);
Download (untitled) / with headers
text/plain 405b
On Wed Nov 23 06:39:55 2011, chrishammond wrote: Show quoted text
> Actually, ignore this line, not required. > + char *pcTemp = strdup(arg);
I've created a repository on github and merged your changes and tagged 1.02. https://github.com/redhotpenguin/String-Strip I also made a request for comaintainership, so hopefully I'll be able to upload this fixed version to CPAN soon. Feel free to make github pulls etc.
Patch applied, thank you Chris. 1.02 is on the way to CPAN, and I am now a comaintainer.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.