[Mesa-dev] [PATCH 3/4] glsl: Create a standalone executable for testing optimization passes.

Chad Versace chad at chad-versace.us
Wed Jul 20 08:00:11 PDT 2011


On 07/19/2011 04:30 PM, Paul Berry wrote:
> On 19 July 2011 13:15, Ian Romanick <idr at freedesktop.org> wrote:

On the issue of std::stringbuf, I'm siding with Paul here. This
concise, safe function definition:

static string read_stdin_to_eof()
{
   stringbuf sb;
   cin.get(sb, '\0');
   return sb.str();
}

is vastly more palatable than this bug-prone mess:

> static char *read_stdin_to_eof()
> {
>   char buffer[4096] = "\0";
>   size_t len = 0;
>   char *result = (char *) malloc(1);
>   while(fgets(buffer, sizeof(buffer), stdin))
>   {
>     size_t bytes_read = strlen(buffer);
>     result = (char *) realloc(result, len + bytes_read + 1);
>     memcpy(result + len, buffer, bytes_read);
>     len += bytes_read;
>   }
>   result[len] = '\0';
>   return result;
> }

-- 
Chad Versace
chad at chad-versace.us

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 900 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20110720/b186495a/attachment.pgp>


More information about the mesa-dev mailing list