From DONOTREPLY at icculus.org Mon Mar 9 14:04:35 2015 From: DONOTREPLY at icculus.org (DONOTREPLY at icculus.org) Date: 9 Mar 2015 18:04:35 -0000 Subject: [rott-commits] r287 - trunk/rott Message-ID: <20150309180435.24356.qmail@icculus.org> Author: fabian Date: 2015-03-09 14:04:35 -0400 (Mon, 09 Mar 2015) New Revision: 287 Modified: trunk/rott/rt_cfg.c trunk/rott/rt_cfg.h trunk/rott/rt_game.c trunk/rott/rt_main.c trunk/rott/rt_ted.c trunk/rott/rt_util.c Log: First attempt to eliminate fixed-size string, ne char[], variables This commit makes the "-filertl" and "-filertc" parameters work with file names of any lengths. It is not yet complete, though. Modified: trunk/rott/rt_cfg.c =================================================================== --- trunk/rott/rt_cfg.c 2015-02-24 17:09:53 UTC (rev 286) +++ trunk/rott/rt_cfg.c 2015-03-09 18:04:35 UTC (rev 287) @@ -2048,13 +2048,12 @@ void GetAlternatePath (char * tokenstr, AlternateInformation *info) { - strcpy (&info->path[0], ".\0"); + info->path = "."; GetToken (true); if (!stricmp (token, tokenstr)) { GetTokenEOL (false); - memset (&info->path[0], 0, sizeof (info->path)); - strcpy (&info->path[0], &name[0]); + info->path = strdup(name); } } @@ -2069,7 +2068,7 @@ { // Read in remote sound file // - strcpy (&info->file[0], "foo.foo\0"); + info->file = "foo.foo"; GetToken (true); if (!stricmp (token, tokenstr)) { @@ -2080,11 +2079,10 @@ { #if (SHAREWARE == 0) info->avail = true; - memset (&info->file[0], 0, sizeof (info->file)); - strcpy (&info->file[0], &token[0]); + info->file = strdup(token); #else printf("Alternate file %s ignored.\n",token); - memset (&info->file[0], 0, sizeof (info->file)); + info->file = ""; #endif } } Modified: trunk/rott/rt_cfg.h =================================================================== --- trunk/rott/rt_cfg.h 2015-02-24 17:09:53 UTC (rev 286) +++ trunk/rott/rt_cfg.h 2015-03-09 18:04:35 UTC (rev 287) @@ -75,9 +75,9 @@ typedef struct { - char path[41]; + char *path; boolean avail; - char file[14]; + char *file; } AlternateInformation; extern AlternateInformation RemoteSounds; Modified: trunk/rott/rt_game.c =================================================================== --- trunk/rott/rt_game.c 2015-02-24 17:09:53 UTC (rev 286) +++ trunk/rott/rt_game.c 2015-03-09 18:04:35 UTC (rev 287) @@ -4854,8 +4854,8 @@ memset (&game->info, 0, sizeof (game->info)); if (GameLevels.avail == true) { - memcpy (&game->info.path[0], &GameLevels.path[0], sizeof (GameLevels.path)); - memcpy (&game->info.file[0], &GameLevels.file[0], sizeof (GameLevels.file)); + game->info.path = GameLevels.path; + game->info.file = GameLevels.file; game->info.avail = true; } Modified: trunk/rott/rt_main.c =================================================================== --- trunk/rott/rt_main.c 2015-02-24 17:09:53 UTC (rev 286) +++ trunk/rott/rt_main.c 2015-03-09 18:04:35 UTC (rev 287) @@ -842,7 +842,7 @@ { char *newargs[99]; int i, arg, argnum = 0; - char tempstr[129]; + char *tempstr = NULL; char *PStrings[] = {"AIM", "FULLSCREEN", "WINDOW", "RESOLUTION", NULL }; // These must be checked here so that they can override the cfg file @@ -888,8 +888,9 @@ arg = CheckParm ("filertl"); if (arg!=0) { - FILE *f;char buf[32]; + FILE *f;char *buf = malloc(32); if (_argv[arg+1] != 0) { //are there a filename included + tempstr = realloc(tempstr, 129 + strlen(_argv[arg+1])); strcpy (tempstr,_argv[arg+1]);//copy it to tempstr if (strlen (tempstr) < MAX_PATH) { if (access (tempstr, 0) != 0) { //try open @@ -908,8 +909,9 @@ }else{ fread(buf,3,3,f);//is the 3 first letters RTL (RTC) if (((strstr(buf,"RTL") != 0)||strstr(buf,"RTC") != 0)) { - strcpy (GameLevels.file,tempstr); + GameLevels.file = strdup(tempstr); GameLevels.avail++; + buf = realloc(buf, 32 + strlen(tempstr)); strcpy (buf,"Adding "); strcat (buf,tempstr); printf("%s", buf); @@ -918,6 +920,7 @@ } } }else{printf("Missing RTL filename");} + free(buf); } NoRTL:; // Check for rtc files @@ -924,8 +927,9 @@ arg = CheckParm ("filertc"); if (arg!=0) { - FILE *f;char buf[32]; + FILE *f;char *buf = malloc(32); if (_argv[arg+1] != 0) { //are there a filename included + tempstr = realloc(tempstr, 129 + strlen(_argv[arg+1])); strcpy (tempstr,_argv[arg+1]);//copy it to tempstr if (strlen (tempstr) < MAX_PATH) { if (access (tempstr, 0) != 0) { //try open @@ -944,8 +948,9 @@ }else{ fread(buf,3,3,f);//is the 3 first letters RTL (RTC) if (((strstr(buf,"RTL") != 0)||strstr(buf,"RTC") != 0)) { - strcpy (BattleLevels.file,tempstr); + BattleLevels.file = strdup(tempstr); BattleLevels.avail++; + buf = realloc(buf, 32 + strlen(tempstr)); strcpy (buf,"Adding "); strcat (buf,tempstr); printf("%s", buf); @@ -954,6 +959,7 @@ } } }else{printf("Missing RTC filename");} + free(buf); } NoRTC:; @@ -1002,12 +1008,13 @@ { char *src; + tempstr = realloc(tempstr, strlen(RemoteSounds.path) + strlen(RemoteSounds.file) + 2); strcpy (tempstr,RemoteSounds.path); src = RemoteSounds.path + strlen(RemoteSounds.path) - 1; if (*src != '\\') strcat (tempstr,"\\\0"); strcat (tempstr,RemoteSounds.file); - newargs [argnum++] = tempstr; + newargs [argnum++] = strdup(tempstr); } else { @@ -1014,6 +1021,9 @@ newargs [argnum++] = DATADIR "REMOTE1.RTS"; } + if (tempstr) + free(tempstr); + newargs [argnum++] = NULL; W_InitMultipleFiles(newargs); Modified: trunk/rott/rt_ted.c =================================================================== --- trunk/rott/rt_ted.c 2015-02-24 17:09:53 UTC (rev 286) +++ trunk/rott/rt_ted.c 2015-03-09 18:04:35 UTC (rev 287) @@ -1669,8 +1669,7 @@ void SetBattleMapFileName ( char * filename ) { BattleLevels.avail = true; - memset (&(BattleLevels.file[0]), 0, sizeof (BattleLevels.file)); - strcpy (&(BattleLevels.file[0]), filename); + BattleLevels.file = strdup(filename); } /* Modified: trunk/rott/rt_util.c =================================================================== --- trunk/rott/rt_util.c 2015-02-24 17:09:53 UTC (rev 286) +++ trunk/rott/rt_util.c 2015-03-09 18:04:35 UTC (rev 287) @@ -1851,7 +1851,7 @@ return (true); #else - if (!*path) { + if (!path || !*path) { return true; }