Method: Crypt::PureRubyStringIO#truncate
- Defined in:
- lib/flatulent/crypt/purerubystringio.rb
#truncate(integer) ⇒ Object
In ruby 1.8.4 truncate differs from the docs in two ways. First, if an integer greater that the length is given then the string is expanded to the new integer length. As this expansion seems to contain junk characters instead of nulls I suspect this may be a flaw in the C code which could cause a core dump if abused/used. Second, the documentation states that truncate returns 0. It returns the integer instead. This implementation follows the documentation in the first instance as I suspect this will be fixed in the C code. In the second instance, it follows the actions of the C code instead of the docs. This was decided as it causes no immedeate harm and this ruby implentation is to be as compatable as possible with the C version. Should the C version change to match the docs the ruby version will be simple to update as well.
334 335 336 337 338 339 |
# File 'lib/flatulent/crypt/purerubystringio.rb', line 334 def truncate(integer) requireWritable raise Errno::EINVAL, "Invalid argument - negative length", caller if integer < 0 @sio_string[[integer, @sio_string.length].max..-1] = "" integer end |