buglet in FileDescriptor>>pastEnd

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

buglet in FileDescriptor>>pastEnd

Stefan Schmiedl
Interesting things happen when you write to a file, forget to close
it, and then try to read from it ... with ObjectDumper.

ObjectDumpter>>nextByte does no error checking

    nextByte [
        "Return the next byte in the byte array"

        <category: 'private - binary I/O'>
        ^stream next asInteger
    ]

Now according to the docs, stream next answers nil if there is nothing
left, however the error was "FileStream does not understand asInteger"...


diff --git a/kernel/FileDescr.st b/kernel/FileDescr.st
index 043f204..3fd061f 100644
--- a/kernel/FileDescr.st
+++ b/kernel/FileDescr.st
@@ -778,7 +778,7 @@ do arbitrary processing on the files.'>
 
         <category: 'polymorphism'>
        atEnd := true.
-       super pastEnd
+       ^super pastEnd
     ]
 
     nextAvailable: n into: aCollection startingAt: position [

With this patch applied, I get the correct error

UndefinedObject(Object)>>doesNotUnderstand: #asInteger (AnsiExcept.st:1556)
ObjectDumper>>nextByte (ObjDumper.st:644)
ObjectDumper>>loadClass (ObjDumper.st:390)

which still should be caught somewhere in ObjectDumper, I think.

s.


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: buglet in FileDescriptor>>pastEnd

Paolo Bonzini-2
> With this patch applied, I get the correct error
>
> UndefinedObject(Object)>>doesNotUnderstand: #asInteger (AnsiExcept.st:1556)
> ObjectDumper>>nextByte (ObjDumper.st:644)
> ObjectDumper>>loadClass (ObjDumper.st:390)
>
> which still should be caught somewhere in ObjectDumper, I think.

This should suffice, any other place where we find an end-of-file
identifies an error in the binary stream and does not need to be
handled -- does it?

diff --git a/kernel/ObjDumper.st b/kernel/ObjDumper.st
index 88a6f54..12a6e4c 100644
--- a/kernel/ObjDumper.st
+++ b/kernel/ObjDumper.st
@@ -293,6 +293,7 @@
  "Special-case metaclasses and other objects"

  | index |
+ stream atEnd ifTrue: [^self pastEnd].
  index := self nextLong.
  ^index < 0
     ifTrue: [self specialCaseLoad: index]

Paolo


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk