Changeset 2570


Ignore:
Timestamp:
Mar 8, 2013, 3:56:06 PM (10 years ago)
Author:
sam
Message:

sys: don't read files on the stack; either we'll overflow or we'll be slow.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sys/file.cpp

    r2568 r2570  
    1919
    2020#include "core.h"
    21 
    22 /* HACK: use fopen() for now so that we get FIOS. */
    23 #if 0//__CELLOS_LV2__
    24 extern "C" {
    25 #   include <stdio.h>
    26 }
    27 #   undef __CELLOS_LV2__
    28 #   define HAVE_STDIO_H 1
    29 #   undef BUFSIZ
    30 #   define BUFSIZ 1024
    31 #endif
    3221
    3322namespace lol
     
    8271    String ReadString()
    8372    {
     73        Array<uint8_t> buf;
     74        buf.Resize(BUFSIZ);
    8475        String ret;
    8576        while (IsValid())
    8677        {
    87             /* XXX: BUFSIZ would overflow the stack here */
    88             uint8_t buf[1024];
    89             int done = Read(buf, 1024);
     78            int done = Read(&buf[0], buf.Count());
    9079
    9180            if (done <= 0)
     
    9483            int oldsize = ret.Count();
    9584            ret.Resize(oldsize + done);
    96             memcpy(&ret[oldsize], buf, done);
     85            memcpy(&ret[oldsize], &buf[0], done);
     86
     87            /* XXX: we could resize the buffer here
     88             * buf.Resize(buf.Count() * 3 / 2); */
    9789        }
    9890        return ret;
Note: See TracChangeset for help on using the changeset viewer.