pike.git / src / program.c

version» Context lines:

pike.git/src/program.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: program.c,v 1.756 2008/09/15 14:46:54 grubba Exp $ + || $Id: program.c,v 1.757 2008/12/15 21:46:09 mast Exp $   */      #include "global.h"   #include "program.h"   #include "object.h"   #include "dynamic_buffer.h"   #include "pike_types.h"   #include "stralloc.h"   #include "las.h"   #include "lex.h"
pike.git/src/program.c:6701:    memcpy(str->str, file, len<<shift);    return end_shared_string(str);    }    }       return NULL;   }      static char *make_plain_file (char *file, size_t len, INT32 shift, int malloced)   { +  static char buf[1000];    if(shift)    { -  static char buf[1000]; -  char *buffer = malloced ? -  malloc (len + 1) : (len = NELEM(buf) - 1, buf); +  size_t bufsize; +  char *buffer;    PCHARP from=MKPCHARP(file, shift); -  int chr; +     size_t ptr=0;    -  for (; (chr = EXTRACT_PCHARP(from)); INC_PCHARP(from, 1)) +  if (malloced) { +  bufsize = len + 1; +  buffer = malloc (bufsize); +  } +  else { +  bufsize = NELEM(buf) - 1; +  buffer = buf; +  } +  +  for (; len--; INC_PCHARP(from, 1))    { -  size_t space = chr > 255 ? 20 : 1; +  size_t space; +  int chr = EXTRACT_PCHARP(from); +  space = chr > 255 ? 20 : 1;    -  if (ptr + space > len) { -  if (malloced) -  buffer = realloc (buffer, (len = (len << 1) + space) + 1); +  if (ptr + space > bufsize) { +  if (malloced) { +  bufsize = (bufsize << 1) + space + 1; +  buffer = realloc (buffer, bufsize); +  }    else    break;    }       if(chr > 255)    {    sprintf(buffer+ptr,"\\u%04X",chr);    ptr+=strlen(buffer+ptr);    }else{    buffer[ptr++]=chr;    }    }       buffer[ptr]=0;    return buffer;    }       else{ -  char *buffer = malloc (len + 1); +  char *buffer; +  if (malloced) +  buffer = malloc (len + 1); +  else { +  buffer = buf; +  if (len > NELEM (buf) - 1) +  len = NELEM (buf) - 1; +  }    MEMCPY (buffer, file, len);    buffer[len] = 0;    return buffer;    }   }      /* Same as low_get_program_line but returns a plain char *. It's    * malloced if the malloced flag is set, otherwise it's a pointer to a    * static buffer which might be clobbered by later calls.    *