Permalink
Browse files

* sizeof(char) is always 1. No need to keep it around.

  • Loading branch information...
1 parent 8a843cf commit ce696881706fa8256ecb12e3e2edf0a2df07e941 BTAxis committed Sep 6, 2012
Showing with 28 additions and 28 deletions.
  1. +1 −1 src/ai.c
  2. +3 −3 src/base64.c
  3. +1 −1 src/dev_planet.c
  4. +4 −4 src/dev_sysedit.c
  5. +1 −1 src/dev_system.c
  6. +2 −2 src/dev_uniedit.c
  7. +2 −2 src/equipment.c
  8. +1 −1 src/info.c
  9. +1 −1 src/ndata.c
  10. +2 −2 src/nfile.c
  11. +1 −1 src/nlua.c
  12. +1 −1 src/options.c
  13. +1 −1 src/outfit.c
  14. +1 −1 src/pack.c
  15. +1 −1 src/pilot_outfit.c
  16. +2 −2 src/ship.c
  17. +3 −3 src/space.c
View
@@ -727,7 +727,7 @@ static int ai_loadProfile( const char* filename )
/* Set name. */
len = strlen(filename)-strlen(AI_PATH)-strlen(AI_SUFFIX);
- prof->name = malloc(sizeof(char)*(len+1) );
+ prof->name = malloc(len+1);
strncpy( prof->name, &filename[strlen(AI_PATH)], len );
prof->name[len] = '\0';
View
@@ -164,7 +164,7 @@ char* base64_encode( size_t *len, char *src, size_t sz )
/* create r */
c = sz * 4 / 3 + sz % 3 + 2;
c += c / 76;
- r = malloc( c * sizeof(char) );
+ r = malloc( c );
/* setup padding */
pad = ((sz % 3) == 0) ? 0 : 3 - sz % 3;
@@ -217,11 +217,11 @@ char* base64_decode( size_t *len, char *src, size_t sz )
/* allocate r */
c = sz * 3 / 4 + 2;
- r = malloc( c * sizeof(char) );
+ r = malloc( c );
/* create a clean version of the text */
pad = 0;
- dat = malloc( sz * sizeof(char) );
+ dat = malloc( sz );
j = 0;
for (i=0; i<sz; i++) {
if (src[i] == '=') /* control padding */
View
@@ -132,7 +132,7 @@ int dpl_savePlanet( const Planet *p )
/* Write data. */
cleanName = uniedit_nameFilter( p->name );
len = strlen(cleanName)+16;
- file = malloc( len*sizeof(char) );
+ file = malloc( len );
nsnprintf( file, len, "dat/assets/%s.xml", cleanName );
xmlSaveFileEnc( file, doc, "UTF-8" );
free( file );
View
@@ -395,9 +395,9 @@ static void sysedit_btnRename( unsigned int wid_unused, char *unused )
}
/* Rename. */
- oldName = malloc((16+strlen(p->name))*sizeof(char));
+ oldName = malloc(16+strlen(p->name));
nsnprintf(oldName,16+strlen(p->name),"dat/assets/%s.xml", uniedit_nameFilter(p->name) );
- newName = malloc((16+strlen(name))*sizeof(char));
+ newName = malloc(16+strlen(name));
nsnprintf(newName,16+strlen(name),"dat/assets/%s.xml", uniedit_nameFilter(name) );
nfile_rename(oldName,newName);
free(oldName);
@@ -427,8 +427,8 @@ static void sysedit_btnRemove( unsigned int wid_unused, char *unused )
sel = &sysedit_select[i];
if (sel->type == SELECT_PLANET) {
cleanName = uniedit_nameFilter( sysedit_sys->planets[ sel->u.planet ]->name );
- file = malloc(16+strlen(cleanName)*sizeof(char));
- nsnprintf(file,16+strlen(cleanName)*sizeof(char),
+ file = malloc(16+strlen(cleanName));
+ nsnprintf(file,16+strlen(cleanName),
"dat/assets/%s.xml",cleanName);
nfile_delete(file);
system_rmPlanet( sysedit_sys, sysedit_sys->planets[ sel->u.planet ]->name );
View
@@ -173,7 +173,7 @@ int dsys_saveSystem( StarSystem *sys )
/* Write data. */
cleanName = uniedit_nameFilter( sys->name );
len = (strlen(cleanName)+14);
- file = malloc( len * sizeof(char) );
+ file = malloc( len );
nsnprintf( file, len, "dat/ssys/%s.xml", cleanName );
xmlSaveFileEnc( file, doc, "UTF-8" );
free( file );
View
@@ -591,7 +591,7 @@ char *uniedit_nameFilter( char *name )
int i, pos;
char *out;
- out = calloc( 1, (strlen(name)+1) * sizeof(char) );
+ out = calloc( 1, (strlen(name)+1) );
pos = 0;
for (i=0; i<(int)strlen(name); i++) {
if (!ispunct(name[i])) {
@@ -634,7 +634,7 @@ static void uniedit_renameSys (void)
}
/* Change the name. */
- oldName = malloc((14+strlen(sys->name))*sizeof(char));
+ oldName = malloc((14+strlen(sys->name)));
nsnprintf(oldName,14+strlen(sys->name),"dat/ssys/%s.xml", uniedit_nameFilter(sys->name) );
newName = malloc((14+strlen(name))*sizeof(char));
nsnprintf(newName,14+strlen(name),"dat/ssys/%s.xml", uniedit_nameFilter(name) );
View
@@ -1373,7 +1373,7 @@ static void equipment_genShipList( unsigned int wid )
alt = malloc( sizeof(char*) * nships );
for (i=0; i<nships; i++) {
s = player_getShip( sships[i] );
- alt[i] = malloc( sizeof(char) * SHIP_ALT_MAX );
+ alt[i] = malloc( SHIP_ALT_MAX );
l = nsnprintf( &alt[i][0], SHIP_ALT_MAX, "Ship Stats\n" );
l = equipment_shipStats( &alt[i][l], SHIP_ALT_MAX-l, s, 1 );
if (l == 0) {
@@ -1535,7 +1535,7 @@ static void equipment_addOutfitListSingle( unsigned int wid,
if ((strcmp(outfit_slotName(o),"NA") != 0) &&
(strcmp(outfit_slotName(o),"NULL") != 0)) {
typename = outfit_slotName(o);
- slottype[i] = malloc( sizeof(char)*2 );
+ slottype[i] = malloc( 2 );
slottype[i][0] = typename[0];
slottype[i][1] = '\0';
}
View
@@ -727,7 +727,7 @@ static void cargo_genList( unsigned int wid )
/* List the player's cargo */
buf = malloc(sizeof(char*)*player.p->ncommodities);
for (i=0; i<player.p->ncommodities; i++) {
- buf[i] = malloc(sizeof(char)*128);
+ buf[i] = malloc(128);
nsnprintf(buf[i],128, "%s%s %d",
player.p->commodities[i].commodity->name,
(player.p->commodities[i].id != 0) ? "*" : "",
View
@@ -769,7 +769,7 @@ static char **stripPath( const char **list, int nlist, const char *path )
/* Slash-terminate as needed. */
if (strcmp(&path[len],"/")!=0) {
len++;
- buf = malloc((len + 1) * sizeof(char));
+ buf = malloc(len + 1);
nsnprintf(buf, len+1, "%s/", path );
}
else
View
@@ -610,12 +610,12 @@ char** nfile_readDirRecursive( int* nfiles, const char* path, ... )
for (i=0; i<tmp; i++) {
ls = strlen(base) + strlen(tfiles[i]) + 1;
- buf = malloc(ls * sizeof(char));
+ buf = malloc(ls);
nsnprintf( buf, ls, "%s%s", path, tfiles[i] );
if (nfile_dirExists(buf)) {
/* Append slash if necessary. */
if (strcmp(&buf[ls-1],"/")!=0) {
- buf = realloc( buf, (ls+1) * sizeof(char) );
+ buf = realloc( buf, (ls+1) );
nsnprintf( buf, ls+1, "%s%s/", path, tfiles[i] );
}
View
@@ -164,7 +164,7 @@ static int nlua_packfileLoader( lua_State* L )
else {
/* Try to locate the data in the data path */
len = strlen(LUA_INCLUDE_PATH)+strlen(filename)+2;
- path_filename = malloc( len * sizeof(char) );
+ path_filename = malloc( len );
nsnprintf( path_filename, len, "%s%s", LUA_INCLUDE_PATH, filename );
if (ndata_exists( path_filename ))
buf = ndata_read( path_filename, &bufsize );
View
@@ -484,7 +484,7 @@ static void menuKeybinds_genList( unsigned int wid )
str = malloc(sizeof(char*) * i);
for (j=0; j < i; j++) {
l = 64;
- str[j] = malloc(sizeof(char) * l);
+ str[j] = malloc(l);
key = input_getKeybind( keybind_info[j][0], &type, &mod );
switch (type) {
case KEYBIND_KEYBOARD:
View
@@ -2208,7 +2208,7 @@ int outfit_mapParse (void)
for (i=0; i<(int)nfiles; i++) {
len = strlen(MAP_DATA_PATH)+strlen(map_files[i])+2;
- file = malloc( len*sizeof(char) );
+ file = malloc( len );
nsnprintf( file, len, "%s%s", MAP_DATA_PATH, map_files[i] );
buf = ndata_read( file, &bufsize );
View
@@ -881,7 +881,7 @@ char** pack_listfiles( const char* packfile, uint32_t* nfiles )
filenames = malloc(((*nfiles)+1)*sizeof(char*));
for (i=0; i<*nfiles; i++) { /* start to search files */
j = 0;
- filenames[i] = malloc(PATH_MAX*sizeof(char));
+ filenames[i] = malloc(PATH_MAX);
READ( &file, &filenames[i][j], 1 ); /* get the name */
while ( filenames[i][j++] != '\0' )
READ( &file, &filenames[i][j], 1 );
View
@@ -767,7 +767,7 @@ char* pilot_getOutfits( const Pilot* pilot )
len = 1024;
- buf = malloc(sizeof(char)*len);
+ buf = malloc(len);
buf[0] = '\0';
p = 0;
for (i=1; i<pilot->noutfits; i++) {
View
@@ -829,7 +829,7 @@ static int ship_parse( Ship *temp, xmlNodePtr parent )
/* Create description. */
if (temp->stats != NULL) {
- temp->desc_stats = malloc( sizeof(char)*STATS_DESC_MAX );
+ temp->desc_stats = malloc( STATS_DESC_MAX );
i = ss_statsListDesc( temp->stats, temp->desc_stats, STATS_DESC_MAX, 0 );
if (i <= 0) {
free( temp->desc_stats );
@@ -906,7 +906,7 @@ int ships_load (void)
/* Get the file name .*/
sl = strlen(SHIP_DATA_PATH)+strlen(ship_files[i])+1;
- file = malloc( sl*sizeof(char) );
+ file = malloc( sl );
nsnprintf( file, sl, "%s%s", SHIP_DATA_PATH, ship_files[i] );
/* Load the XML. */
View
@@ -1491,7 +1491,7 @@ static int planets_load ( void )
planet_files = ndata_list( PLANET_DATA_PATH, &nfiles );
for (i=0; i<(int)nfiles; i++) {
len = (strlen(PLANET_DATA_PATH)+strlen(planet_files[i])+2);
- file = malloc( len * sizeof(char) );
+ file = malloc( len );
nsnprintf( file, len,"%s%s",PLANET_DATA_PATH,planet_files[i]);
buf = ndata_read( file, &bufsize );
doc = xmlParseMemory( buf, bufsize );
@@ -2693,7 +2693,7 @@ static int systems_load (void)
for (i=0; i<(int)nfiles; i++) {
len = strlen(SYSTEM_DATA_PATH)+strlen(system_files[i])+2;
- file = malloc( len * sizeof(char) );
+ file = malloc( len );
nsnprintf( file, len, "%s%s", SYSTEM_DATA_PATH, system_files[i] );
/* Load the file. */
buf = ndata_read( file, &bufsize );
@@ -2727,7 +2727,7 @@ static int systems_load (void)
for (i=0; i<(int)nfiles; i++) {
len = strlen(SYSTEM_DATA_PATH)+strlen(system_files[i])+2;
- file = malloc( len * sizeof(char) );
+ file = malloc( len );
nsnprintf( file, len, "%s%s", SYSTEM_DATA_PATH, system_files[i] );
/* Load the file. */
buf = ndata_read( file, &bufsize );

0 comments on commit ce69688

Please sign in to comment.