Changeset 131 for abuse/trunk


Ignore:
Timestamp:
Mar 22, 2008, 11:03:33 AM (15 years ago)
Author:
Sam Hocevar
Message:
  • Use strdup(foo) everywhere instead of strcpy(malloc(strlen(foo)+1),foo);
Location:
abuse/trunk/src
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/src/cache.cpp

    r129 r131  
    1515
    1616#include <fcntl.h>
     17#include <string.h>
    1718
    1819#include "cache.hpp"
     
    139140CrcedFile::CrcedFile(char const *name)
    140141{
    141   filename=strcpy((char *)malloc(strlen(name)+1),name);
     142  filename = strdup(name);
    142143  crc_calculated=0;
    143144}
  • abuse/trunk/src/chars.hpp

    r129 r131  
    1111#define __CHARACTERZ_HPP_
    1212
     13#include <string.h>
    1314
    1415#include "seq.hpp"
     
    2122
    2223
    23 enum character_state {dead,
    24               dieing,
    25               stopped,       
    26               start_run_jump,run_jump, run_jump_fall, end_run_jump,
    27               flinch_up,flinch_down,
    28               morph_pose,
    29               running
    30             } ;
    31 
    32 
     24enum character_state
     25{
     26    dead,
     27    dieing,
     28    stopped,       
     29    start_run_jump, run_jump, run_jump_fall, end_run_jump,
     30    flinch_up, flinch_down,
     31    morph_pose,
     32    running
     33};
    3334
    3435#define MAX_STATE (running+1)
     
    4142  char *descript_name;
    4243  named_field(char *real, char *fake)
    43   { real_name=strcpy((char *)malloc(strlen(real) + 1),real);
    44     descript_name=strcpy((char *)malloc(strlen(fake) + 1),fake);
     44  { real_name = strdup(real);
     45    descript_name = strdup(fake);
    4546  }
    4647  ~named_field() { free(real_name); free(descript_name); }
  • abuse/trunk/src/clisp.cpp

    r129 r131  
    99
    1010#include "config.h"
     11
     12#include <string.h>
    1113
    1214#include "sdlport/joy.hpp"
     
    779781      }
    780782
    781       object_names[total_objects]=strcpy(
    782       (char *)malloc(strlen(lstring_value(symbol_name(sym)))+1),
    783                      lstring_value(symbol_name(sym)));
     783      object_names[total_objects] = strdup(lstring_value(symbol_name(sym)));
    784784      figures[total_objects]=new character_type(CDR(args),sym);
    785785      total_objects++;
  • abuse/trunk/src/console.cpp

    r129 r131  
    1212#include <ctype.h>
    1313#include <stdarg.h>
     14#include <string.h>
    1415
    1516#include "game.hpp"
     
    8586  lastx=xres/2-screen_w()/2;
    8687  lasty=yres/2-screen_h()/2;
    87   name=(char *)strcpy((char *)malloc(strlen(Name)+1),Name);
     88  name = strdup(Name);
    8889}
    8990
  • abuse/trunk/src/dev.cpp

    r129 r131  
    1111
    1212#include <ctype.h>
     13#include <string.h>
    1314
    1415#include "dev.hpp"
     
    29262927  Cell *ao=(Cell *)args;
    29272928
    2928   name=strcpy((char *)malloc(strlen(lstring_value(CAR(args)))+1),lstring_value(CAR(args)));
     2929  name = strdup(lstring_value(CAR(args)));
    29292930  ao=CDR(ao);
    29302931  scale=w=h=1;
  • abuse/trunk/src/imlib/guistat.cpp

    r129 r131  
    99
    1010#include "config.h"
     11
     12#include <string.h>
    1113
    1214#include "input.hpp"
     
    2527  time_marker last_time;
    2628  gui_status_node(char const *Name, visual_object *Show, gui_status_node *Next)
    27   { name=strcpy((char *)malloc(strlen(Name)+1),Name);
     29  { name = strdup(Name);
    2830    show=Show;
    2931    next=Next;
  • abuse/trunk/src/imlib/input.cpp

    r129 r131  
    99
    1010#include "config.h"
     11
     12#include <string.h>
    1113
    1214#include "input.hpp"
     
    221223  x=X; y=Y; id=ID;
    222224  act_id=-1;
    223   text=strcpy((char *)malloc(strlen(Text)+1),Text);
     225  text = strdup(Text);
    224226  up=1; next=Next; act=0;
    225227  visual=NULL;
     
    334336
    335337  x=X; y=Y; id=ID;
    336   prompt=strcpy((char *)malloc(strlen(Prompt)+1),Prompt);
     338  prompt = strdup(Prompt);
    337339  format=strcpy((char *)malloc(slen+1),Format);
    338340  data=strcpy((char *)malloc(slen+1),Data);
     
    349351  int slen=(strlen(Format)>strlen(num) ? strlen(Format) : strlen(num));
    350352  x=X; y=Y; id=ID;
    351   prompt=strcpy((char *)malloc(strlen(Prompt)+1),Prompt);
     353  prompt = strdup(Prompt);
    352354  format=strcpy((char *)malloc(slen+1),Format);
    353355  data=strcpy((char *)malloc(slen+1),num);
     
    460462{
    461463  x = X; y = Y; id = ID; next = Next;
    462   text = strcpy((char *)malloc(strlen(info)+1), info);
     464  text = strdup(info);
    463465  w = -1;
    464466}
  • abuse/trunk/src/imlib/jwindow.cpp

    r129 r131  
    99
    1010#include "config.h"
     11
     12#include <string.h>
    1113
    1214#include "video.hpp"
     
    394396    _name = NULL;
    395397    if(name)
    396         _name = strcpy((char *)malloc(strlen(name) + 1), name);
     398        _name = strdup(name);
    397399    wm->add_window(this);
    398400}
     
    440442    _name = NULL;
    441443    if(name)
    442         _name = strcpy((char *)malloc(strlen(name) + 1), name);
     444        _name = strdup(name);
    443445
    444446    wm->add_window(this);
  • abuse/trunk/src/imlib/pmenu.cpp

    r129 r131  
    1010#include "config.h"
    1111
     12#include <string.h>
     13
    1214#include "pmenu.hpp"
    1315
     
    6062  on_off=on_off_flag;
    6163  if (Name)
    62     n=strcpy((char *)malloc(strlen(Name)+1),Name);
     64    n = strdup(Name);
    6365  else n=NULL;
    6466  next=Next;
     
    7375  on_off=NULL;
    7476  CONDITION(Name,"Sub menu cannot have a NULL name");
    75   n=strcpy((char *)malloc(strlen(Name)+1),Name);
     77  n = strdup(Name);
    7678  sub=Sub;
    7779}
  • abuse/trunk/src/imlib/specs.hpp

    r129 r131  
    1010#ifndef __SPECS_HPP_
    1111#define __SPECS_HPP_
     12
    1213#include <stdio.h>
    1314#include <fcntl.h>
    1415#include <stdlib.h>
    1516#include <stdint.h>
     17#include <string.h>
    1618
    1719#include "linked.hpp"
     
    156158             unsigned long data_size,
    157159             unsigned long data_offset)
    158   { type=spec_type;
    159     name=strcpy((char *)malloc(strlen(object_name) + 1),object_name);
    160     size=data_size; offset=data_offset;
     160  { type = spec_type;
     161    name = strdup(object_name);
     162    size = data_size;
     163    offset = data_offset;
    161164  }
    162165  void print();
  • abuse/trunk/src/imlib/status.cpp

    r129 r131  
    99
    1010#include "config.h"
     11
     12#include <string.h>
    1113
    1214#include "macs.hpp"
     
    2426  int last_update;
    2527  text_status_node(char const *Name, visual_object *Show, text_status_node *Next)
    26   { name=strcpy((char *)malloc(strlen(Name)+1),Name);
    27     show=Show;
    28     next=Next;
    29     last_update=0;
     28  { name = strdup(Name);
     29    show = Show;
     30    next = Next;
     31    last_update = 0;
    3032  }
    3133  ~text_status_node() { free(name); if (show) delete show; }
  • abuse/trunk/src/imlib/visobj.cpp

    r129 r131  
    99
    1010#include "config.h"
     11
     12#include <string.h>
    1113
    1214#include "input.hpp"
     
    2527string_visual::string_visual(char *string, int Color)
    2628{
    27   st=strcpy((char *)malloc(strlen(string)+1),string);
    28   color=Color;
    29   w=-1;
     29    st = strdup(string);
     30    color = Color;
     31    w = -1;
    3032}
    3133
  • abuse/trunk/src/level.cpp

    r129 r131  
    1414#endif
    1515
     16#include <string.h>
    1617#include <limits.h>
    1718#include <time.h>
     
    12961297  sprintf(cmd,symbol_str("loading"),lev_name);
    12971298  stack_stat stat(cmd);
    1298   Name=strcpy((char *)malloc(strlen(lev_name)+1),lev_name);
     1299  Name = strdup(lev_name);
    12991300
    13001301  e=sd->find("first name");
     
    13071308  } else
    13081309  {
    1309     first_name=(char *)malloc(strlen(Name)+1);
    1310     strcpy(first_name,Name);
     1310    first_name = strdup(Name);
    13111311  }
    13121312
     
    22392239        if( first_name )
    22402240            free(first_name);
    2241         first_name = (char *)malloc( strlen( name ) + 1 );
    2242         strcpy( first_name, name );
     2241        first_name = strdup(name);
    22432242    }
    22442243
  • abuse/trunk/src/oldhelp.cpp

    r129 r131  
    1010#include "config.h"
    1111
     12#include <string.h>
     13
    1214#include "help.hpp"
    1315#include "game.hpp"
     
    4446      if (line[0]=='.')
    4547      {   
    46     fclose(fp);   
    47         return strcpy((char *)malloc(strlen(tmp)+1),tmp);
     48        fclose(fp);   
     49        return strdup(tmp);
    4850      }
    4951      else strcat(tmp,line);
  • abuse/trunk/src/property.cpp

    r129 r131  
    2424  int def_num;
    2525  property(char const *Name, int Def)
    26   { name=strcpy((char *)malloc(strlen(Name)+1),Name);
    27     def_num=Def;
    28     def_str=NULL;
    29     next=NULL;
     26  { name = strdup(Name);
     27    def_num = Def;
     28    def_str = NULL;
     29    next = NULL;
    3030  }
    3131
    3232  property(char const *Name, char const *Def)
    33   { name=strcpy((char *)malloc(strlen(Name)+1),Name);
    34     def_str=strcpy((char *)malloc(strlen(Def)+1),Def);
    35     next=NULL;
     33  { name = strdup(Name);
     34    def_str = strdup(Def);
     35    next = NULL;
    3636  }
    3737
     
    5252      def_str=NULL;
    5353    }
    54     def_str=strcpy((char *)malloc(strlen(x)+1),x);
     54    def_str = strdup(x);
    5555  }
    5656
  • abuse/trunk/src/scene.cpp

    r129 r131  
    1212#include <stdio.h>
    1313#include <stdlib.h>
     14#include <string.h>
    1415#include <ctype.h>
    1516#include <fcntl.h>
     
    3233public :
    3334  string_node(char *Name, string_node *Left=NULL, string_node *Right=NULL)
    34   { l=Left;
    35     r=Right;
    36     n=strcpy((char *)malloc(strlen(Name)+1),Name);
     35  { l = Left;
     36    r = Right;
     37    n = strdup(Name);
    3738  }
    3839  ~string_node() { free(n); }
     
    132133
    133134  expect(get_token(s,tmp_name),sWORD,s);
    134   n=strcpy((char *)malloc(strlen(tmp_name)+1),tmp_name);
    135   cur=first=new scene_frame(s);
     135  n = strdup(tmp_name);
     136  cur = first=new scene_frame(s);
    136137
    137138  while (token_type(s)!=sRIGHT_PAREN)
     
    271272  expect(get_token(s,tmp),sLEFT_PAREN,s);
    272273  expect(get_token(s,tmp),sWORD,s);
    273   n=strcpy((char *)malloc(strlen(tmp)+1),tmp);
     274  n = strdup(tmp);
    274275  expect(get_token(s,tmp),sNUMBER,s);
    275276
  • abuse/trunk/src/sdlport/jdir.cpp

    r129 r131  
    2020#include "config.h"
    2121
    22 #include <sys/types.h>
    2322#include <stdio.h>
    24 #include <dirent.h>
    2523#include <stdlib.h>
    2624#include <string.h>
     25
     26#include <sys/types.h>
     27#include <dirent.h>
    2728#include <unistd.h>
    2829
     
    5253            t++;
    5354            tlist = (char **)realloc(tlist,sizeof(char *)*t);
    54             tlist[t-1] = strcpy((char *)malloc(strlen(de->d_name)+1),de->d_name);
     55            tlist[t-1] = strdup(de->d_name);
    5556        }
    5657    } while( de );
     
    6465            tdirs++;
    6566            dirs = (char **)realloc(dirs,sizeof(char *)*tdirs);
    66             dirs[tdirs-1] = strcpy((char *)malloc(strlen(tlist[i])+1),tlist[i]);
     67            dirs[tdirs-1] = strdup(tlist[i]);
    6768            closedir( d );
    6869        }
     
    7172            tfiles++;
    7273            files = (char **)realloc(files,sizeof(char *)*tfiles);
    73             files[tfiles-1] = strcpy((char *)malloc(strlen(tlist[i])+1),tlist[i]);
     74            files[tfiles-1] = strdup(tlist[i]);
    7475        }
    7576        free( tlist[i] );
  • abuse/trunk/src/sdlport/sound.cpp

    r129 r131  
    1919
    2020#include "config.h"
     21
     22#include <string.h>
    2123
    2224#include <SDL.h>
     
    295297{
    296298    data = NULL;
    297     Name = strcpy((char *)malloc( strlen( filename ) + 1 ), filename );
     299    Name = strdup(filename);
    298300    song_id = 0;
    299301}
  • abuse/trunk/src/specache.hpp

    r129 r131  
    1313#include "specs.hpp"
    1414
     15#include <string.h>
    1516
    1617class spec_directory_cache
     
    2526    filename_node(char const *filename, spec_directory *dir)
    2627    {
    27       fn=(char *)memcpy(malloc(strlen(filename) + 1),filename,strlen(filename)+1);
    28       sd=dir;
    29       next=left=right=0;
     28      fn = strdup(filename);
     29      sd = dir;
     30      next = left = right = 0;
    3031    }
    3132    long size;
  • abuse/trunk/src/status.cpp

    r129 r131  
    99
    1010#include "config.h"
     11
     12#include <string.h>
    1113
    1214#include "macs.hpp"
     
    3941  time_marker last_update;
    4042  status_node(char *Name, visual_object *Show, status_node *Next)
    41   { name=strcpy((char *)malloc(strlen(Name)+1),Name);
    42     show=Show;
    43     next=Next;
     43  { name = strdup(Name);
     44    show = Show;
     45    next = Next;
    4446  }
    4547  ~status_node() { free(name); if (show) delete show; }
Note: See TracChangeset for help on using the changeset viewer.