Bug in String.index?

M

Martin Kahlert

Hi!
Is this a bug or a strange feature?

a = ""
a << 240
puts a[0]
puts a.index(240)

gives:
240
nil

ruby --version:
ruby 1.7.3 (2002-12-16) [i686-linux]
(1.8.1 shows the same behaviour)


Thanks for any workaround in advance
Martin.
 
N

nobu.nokada

Hi,

At Fri, 16 Apr 2004 19:54:15 +0900,
Martin Kahlert wrote in [ruby-talk:97342]:
Is this a bug or a strange feature?

A bug.


Index: string.c
===================================================================
RCS file: /cvs/ruby/src/ruby/string.c,v
retrieving revision 1.190
diff -u -2 -p -r1.190 string.c
--- string.c 14 Apr 2004 04:06:25 -0000 1.190
+++ string.c 16 Apr 2004 11:25:30 -0000
@@ -1079,5 +1079,5 @@ rb_str_index_m(argc, argv, str)
case T_FIXNUM:
{
- int c = FIX2INT(sub);
+ char c = (char)FIX2INT(sub);
long len = RSTRING(str)->len;
char *p = RSTRING(str)->ptr;
@@ -1202,5 +1202,5 @@ rb_str_rindex_m(argc, argv, str)
case T_FIXNUM:
{
- int c = FIX2INT(sub);
+ char c = (char)FIX2INT(sub);
char *p = RSTRING(str)->ptr + pos;
char *pbeg = RSTRING(str)->ptr;
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: Bug in String.index?"

|At Fri, 16 Apr 2004 19:54:15 +0900,
|Martin Kahlert wrote in [ruby-talk:97342]:
|> Is this a bug or a strange feature?
|
|A bug.

Indeed. I will fix.

matz.
 
M

Martin Kahlert

Hi,

Hi,

In message "Re: Bug in String.index?"

|At Fri, 16 Apr 2004 19:54:15 +0900,
|Martin Kahlert wrote in [ruby-talk:97342]:
|> Is this a bug or a strange feature?
|
|A bug.

Indeed. I will fix.

matz.

Thanks a lot for all replies - especially for nobu.nokada's patch!
Will this patch be included into the stable series?
In my today's snapshot it does not work out of the box and the patch seems
not to be in, yet.

Regards
Martin.
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: Bug in String.index?"

|Thanks a lot for all replies - especially for nobu.nokada's patch!
|Will this patch be included into the stable series?
|In my today's snapshot it does not work out of the box and the patch seems
|not to be in, yet.

I'm working on local copy. Wait for a few days.

matz.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top