Handle map path being too long

This commit is contained in:
Camden Dixie O'Brien 2024-12-26 20:05:18 +00:00
parent 296975caa1
commit eaf8df0fb1

View File

@ -7,6 +7,7 @@
#include <assert.h> #include <assert.h>
#include <ctype.h> #include <ctype.h>
#include <libxml/parser.h> #include <libxml/parser.h>
#include <string.h>
#define TILESIZE 32 #define TILESIZE 32
#define WINWIDTH 30 #define WINWIDTH 30
@ -26,6 +27,8 @@ static unsigned map[MAPWIDTH][MAPHEIGHT];
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char path[MAX_PATH_LEN];
if (2 != argc) { if (2 != argc) {
fprintf(stderr, "Usage: %s ASSETS-DIR\n", argv[0]); fprintf(stderr, "Usage: %s ASSETS-DIR\n", argv[0]);
return 1; return 1;
@ -42,10 +45,10 @@ int main(int argc, char *argv[])
xmlDocPtr doc; xmlDocPtr doc;
xmlNodePtr node; xmlNodePtr node;
char mappath[MAX_PATH_LEN]; assert(strlen(argv[1]) + strlen(MAP_ASSET) < MAX_PATH_LEN);
strncpy(mappath, argv[1], MAX_PATH_LEN); strcpy(path, argv[1]);
strncat(mappath, MAP_ASSET, MAX_PATH_LEN); strcat(path, MAP_ASSET);
doc = xmlParseFile(mappath); doc = xmlParseFile(path);
assert(NULL != doc); assert(NULL != doc);
node = xmlDocGetRootElement(doc); node = xmlDocGetRootElement(doc);
assert(0 == xmlStrcmp(node->name, (const xmlChar *)"map")); assert(0 == xmlStrcmp(node->name, (const xmlChar *)"map"));