[BACK]Return to cmd-load-buffer.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Diff for /src/usr.bin/tmux/cmd-load-buffer.c between version 1.10 and 1.11

version 1.10, 2009/11/26 22:32:00 version 1.11, 2010/02/22 20:33:12
Line 16 
Line 16 
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.   * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */   */
   
 #include <sys/types.h>  
 #include <sys/stat.h>  
   
 #include <errno.h>  #include <errno.h>
   #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
 #include <unistd.h>  
   
 #include "tmux.h"  #include "tmux.h"
   
Line 48 
Line 45 
 {  {
         struct cmd_buffer_data  *data = self->data;          struct cmd_buffer_data  *data = self->data;
         struct session          *s;          struct session          *s;
         struct stat              sb;  
         FILE                    *f;          FILE                    *f;
         char                    *pdata = NULL;          char                    *pdata, *new_pdata;
         size_t                   psize;          size_t                   psize;
         u_int                    limit;          u_int                    limit;
           int                      ch;
   
         if ((s = cmd_find_session(ctx, data->target)) == NULL)          if ((s = cmd_find_session(ctx, data->target)) == NULL)
                 return (-1);                  return (-1);
Line 62 
Line 59 
                 return (-1);                  return (-1);
         }          }
   
         if (fstat(fileno(f), &sb) < 0) {          pdata = NULL;
                 ctx->error(ctx, "%s: %s", data->arg, strerror(errno));          psize = 0;
                 goto error;          while ((ch = getc(f)) != EOF) {
                   /* Do not let the server die due to memory exhaustion. */
                   if ((new_pdata = realloc(pdata, psize + 2)) == NULL) {
                           ctx->error(ctx, "realloc error: %s", strerror(errno));
                           goto error;
                   }
                   pdata = new_pdata;
                   pdata[psize++] = ch;
         }          }
         if (sb.st_size <= 0 || (uintmax_t) sb.st_size > SIZE_MAX) {          if (ferror(f)) {
                 ctx->error(ctx, "%s: file empty or too large", data->arg);                  ctx->error(ctx, "%s: read error", data->arg);
                 goto error;                  goto error;
         }          }
         psize = (size_t) sb.st_size;          if (pdata != NULL)
                   pdata[psize] = '\0';
         /*  
          * We don't want to die due to memory exhaustion, hence xmalloc can't  
          * be used here.  
          */  
         if ((pdata = malloc(psize)) == NULL) {  
                 ctx->error(ctx, "malloc error: %s", strerror(errno));  
                 goto error;  
         }  
   
         if (fread(pdata, 1, psize, f) != psize) {  
                 ctx->error(ctx, "%s: fread error", data->arg);  
                 goto error;  
         }  
   
         fclose(f);          fclose(f);
   

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11