mirror of
https://gitea.psi.ch/ELOG/mxml.git
synced 2026-09-09 01:23:22 +00:00
Remove more strcpy()
This commit is contained in:
parent
f09643b9fc
commit
e6e2e64548
24
mxml.cxx
24
mxml.cxx
@ -1685,16 +1685,13 @@ int mxml_parse_entity(char **buf, const char *file_name, char *error, int error_
|
|||||||
int entity_type[MXML_MAX_ENTITY]; /* internal or external */
|
int entity_type[MXML_MAX_ENTITY]; /* internal or external */
|
||||||
int entity_line_number[MXML_MAX_ENTITY];
|
int entity_line_number[MXML_MAX_ENTITY];
|
||||||
int nentity;
|
int nentity;
|
||||||
int fh, length, len;
|
int fh, length;
|
||||||
char *buffer;
|
|
||||||
int ip; /* counter for entity value */
|
|
||||||
char directoryname[FILENAME_MAX];
|
|
||||||
int entity_value_length[MXML_MAX_ENTITY];
|
int entity_value_length[MXML_MAX_ENTITY];
|
||||||
int entity_name_length[MXML_MAX_ENTITY];
|
int entity_name_length[MXML_MAX_ENTITY];
|
||||||
|
|
||||||
PMXML_NODE root = mxml_create_root_node(); /* dummy for 'HERE' */
|
PMXML_NODE root = mxml_create_root_node(); /* dummy for 'HERE' */
|
||||||
|
|
||||||
for (ip = 0; ip < MXML_MAX_ENTITY; ip++)
|
for (int ip = 0; ip < MXML_MAX_ENTITY; ip++)
|
||||||
entity_value[ip] = NULL;
|
entity_value[ip] = NULL;
|
||||||
|
|
||||||
line_number = 1;
|
line_number = 1;
|
||||||
@ -1704,17 +1701,19 @@ int mxml_parse_entity(char **buf, const char *file_name, char *error, int error_
|
|||||||
if (!buf || !(*buf) || !strlen(*buf))
|
if (!buf || !(*buf) || !strlen(*buf))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
strcpy(directoryname, file_name);
|
char directoryname[FILENAME_MAX];
|
||||||
|
mxml_strlcpy(directoryname, file_name, FILENAME_MAX);
|
||||||
mxml_dirname(directoryname);
|
mxml_dirname(directoryname);
|
||||||
|
|
||||||
/* copy string to temporary space */
|
/* copy string to temporary space */
|
||||||
buffer = (char *) mxml_malloc(strlen(*buf) + 1);
|
int len = strlen(*buf);
|
||||||
|
char* buffer = (char *) mxml_malloc(len+1);
|
||||||
if (buffer == NULL) {
|
if (buffer == NULL) {
|
||||||
read_error(HERE, "Cannot allocate memory.");
|
read_error(HERE, "Cannot allocate memory.");
|
||||||
status = 1;
|
status = 1;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
strcpy(buffer, *buf);
|
memcpy(buffer, *buf, len+1);
|
||||||
|
|
||||||
p = strstr(buffer, "!DOCTYPE");
|
p = strstr(buffer, "!DOCTYPE");
|
||||||
if (p == NULL) { /* no entities */
|
if (p == NULL) { /* no entities */
|
||||||
@ -1917,15 +1916,16 @@ int mxml_parse_entity(char **buf, const char *file_name, char *error, int error_
|
|||||||
mxml_decode(replacement);
|
mxml_decode(replacement);
|
||||||
|
|
||||||
if (entity_type[nentity] == EXTERNAL_ENTITY) {
|
if (entity_type[nentity] == EXTERNAL_ENTITY) {
|
||||||
strcpy(entity_reference_name[nentity], replacement);
|
mxml_strlcpy(entity_reference_name[nentity], replacement, sizeof(entity_reference_name[nentity]));
|
||||||
} else {
|
} else {
|
||||||
entity_value[nentity] = (char *) mxml_malloc(strlen(replacement));
|
int rlen = strlen(replacement);
|
||||||
|
entity_value[nentity] = (char *) mxml_malloc(rlen+1);
|
||||||
if (entity_value[nentity] == NULL) {
|
if (entity_value[nentity] == NULL) {
|
||||||
read_error(HERE, "Cannot allocate memory.");
|
read_error(HERE, "Cannot allocate memory.");
|
||||||
status = 1;
|
status = 1;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
strcpy(entity_value[nentity], replacement);
|
memcpy(entity_value[nentity], replacement, rlen+1);
|
||||||
}
|
}
|
||||||
mxml_free(replacement);
|
mxml_free(replacement);
|
||||||
|
|
||||||
@ -2057,7 +2057,7 @@ error:
|
|||||||
|
|
||||||
if (buffer != NULL)
|
if (buffer != NULL)
|
||||||
mxml_free(buffer);
|
mxml_free(buffer);
|
||||||
for (ip = 0; ip < MXML_MAX_ENTITY; ip++)
|
for (int ip = 0; ip < MXML_MAX_ENTITY; ip++)
|
||||||
if (entity_value[ip] != NULL)
|
if (entity_value[ip] != NULL)
|
||||||
mxml_free(entity_value[ip]);
|
mxml_free(entity_value[ip]);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user