Bug #5841

Inccorect calculation in rb_file_join

Added by Benoit Daloze about 3 years ago. Updated about 3 years ago.

[ruby-core:41901]
Status:Closed
Priority:Normal
Assignee:-
ruby -v:ruby 2.0.0dev Backport:

Description

Not really a bug, since the len is only an advice, and sep's len is usually 1 (separator's len), but the logic is not clear:

diff --git a/file.c b/file.c
index fb62c51..15d594a 100644
--- a/file.c
+++ b/file.c
@@ -3825,7 +3825,7 @@ rb_file_join(VALUE ary, VALUE sep)
}
if (!NIL_P(sep)) {
StringValue(sep);
- len += RSTRING_LEN(sep) * RARRAY_LEN(ary) - 1;
+ len += RSTRING_LEN(sep) * (RARRAY_LEN(ary) - 1);
}
result = rb_str_buf_new(len);
OBJ_INFECT(result, ary);

Associated revisions

Revision 34215
Added by Yui NARUSE about 3 years ago

  • file.c (rb_file_join): separator is appended by array length - 1 times. patched by Benoit Daloze [Bug #5841]

Revision 34215
Added by Yui NARUSE about 3 years ago

  • file.c (rb_file_join): separator is appended by array length - 1 times. patched by Benoit Daloze [Bug #5841]

History

#1 Updated by Yui NARUSE about 3 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r34215.
Benoit, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • file.c (rb_file_join): separator is appended by array length - 1 times. patched by Benoit Daloze [Bug #5841]

Also available in: Atom PDF