File tree Expand file tree Collapse file tree 2 files changed +13
-9
lines changed
Expand file tree Collapse file tree 2 files changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -60,9 +60,12 @@ int PycFile::getByte()
6060 return ch;
6161}
6262
63- int PycFile::getBuffer (int bytes, void * buffer)
63+ void PycFile::getBuffer (int bytes, void * buffer)
6464{
65- return (int )fread (buffer, 1 , bytes, m_stream);
65+ if (fread (buffer, 1 , bytes, m_stream) != (size_t )bytes) {
66+ fputs (" PycFile::getBuffer(): Unexpected end of stream\n " , stderr);
67+ std::exit (1 );
68+ }
6669}
6770
6871
@@ -78,14 +81,15 @@ int PycBuffer::getByte()
7881 return ch & 0xFF ; // Make sure it's just a byte!
7982}
8083
81- int PycBuffer::getBuffer (int bytes, void * buffer)
84+ void PycBuffer::getBuffer (int bytes, void * buffer)
8285{
83- if (m_pos + bytes > m_size)
84- bytes = m_size - m_pos;
86+ if (m_pos + bytes > m_size) {
87+ fputs (" PycBuffer::getBuffer(): Unexpected end of stream\n " , stderr);
88+ std::exit (1 );
89+ }
8590 if (bytes != 0 )
8691 memcpy (buffer, (m_buffer + m_pos), bytes);
8792 m_pos += bytes;
88- return bytes;
8993}
9094
9195int formatted_print (std::ostream& stream, const char * format, ...)
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ class PycData {
1919 virtual bool atEof () const = 0;
2020
2121 virtual int getByte () = 0;
22- virtual int getBuffer (int bytes, void * buffer) = 0;
22+ virtual void getBuffer (int bytes, void * buffer) = 0;
2323 int get16 ();
2424 int get32 ();
2525 Pyc_INT64 get64 ();
@@ -34,7 +34,7 @@ class PycFile : public PycData {
3434 bool atEof () const override ;
3535
3636 int getByte () override ;
37- int getBuffer (int bytes, void * buffer) override ;
37+ void getBuffer (int bytes, void * buffer) override ;
3838
3939private:
4040 FILE* m_stream;
@@ -50,7 +50,7 @@ class PycBuffer : public PycData {
5050 bool atEof () const override { return (m_pos == m_size); }
5151
5252 int getByte () override ;
53- int getBuffer (int bytes, void * buffer) override ;
53+ void getBuffer (int bytes, void * buffer) override ;
5454
5555private:
5656 const unsigned char * m_buffer;
You can’t perform that action at this time.
0 commit comments