Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrected malloc statements #514

Merged
merged 8 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions hdf/test/tvnameclass.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ test_vglongnames(void)
status = Vgetnamelen(vg1, &name_len);
CHECK_VOID(status, FAIL, "Vgetnamelen");

vgname = (char *)malloc(sizeof(char *) * (name_len + 1));
vgname = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(vgname, "vgname", "test_vglongnames");

status = Vgetname(vg1, vgname);
Expand All @@ -115,7 +115,7 @@ test_vglongnames(void)
status = Vgetclassnamelen(vg1, &name_len);
CHECK_VOID(status, FAIL, "Vgetnamelen");

vgclass = (char *)malloc(sizeof(char *) * (name_len + 1));
vgclass = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(vgclass, "vgclass", "test_vglongnames");

status = Vgetclass(vg1, vgclass);
Expand All @@ -138,7 +138,7 @@ test_vglongnames(void)
status = Vgetnamelen(vg1, &name_len);
CHECK_VOID(status, FAIL, "Vgetnamelen");

vgname = (char *)malloc(sizeof(char *) * (name_len + 1));
vgname = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(vgname, "vgname", "test_vglongnames");

status = Vgetname(vg1, vgname);
Expand All @@ -155,7 +155,7 @@ test_vglongnames(void)
status = Vgetclassnamelen(vg1, &name_len);
CHECK_VOID(status, FAIL, "Vgetnamelen");

vgclass = (char *)malloc(sizeof(char *) * (name_len + 1));
vgclass = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(vgclass, "vgclass", "test_vglongnames");

status = Vgetclass(vg1, vgclass);
Expand Down
22 changes: 11 additions & 11 deletions hdf/test/tvset.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ read_vset_stuff(void)
status = Vgetnamelen(vg1, &name_len);
CHECK(status, FAIL, "Vgetnamelen:vg1");

vgname = (char *)malloc(sizeof(char *) * (name_len + 1));
vgname = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(vgname, "vgname", "read_vset_stuff");

status = Vgetname(vg1, vgname);
Expand All @@ -604,7 +604,7 @@ read_vset_stuff(void)
status = Vgetclassnamelen(vg1, &name_len);
CHECK(status, FAIL, "Vgetclassnamelen:vg1");

vgclass = (char *)malloc(sizeof(char *) * (name_len + 1));
vgclass = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(vgclass, "vgclass", "read_vset_stuff");

status = Vgetclass(vg1, vgclass);
Expand Down Expand Up @@ -1823,7 +1823,7 @@ test_vglongnames(void)
status = Vgetnamelen(vg1, &name_len);
CHECK_VOID(status, FAIL, "Vgetnamelen");

vgname = (char *)malloc(sizeof(char *) * (name_len + 1));
vgname = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(vgname, "vgname", "test_vglongnames");

status = Vgetname(vg1, vgname);
Expand All @@ -1840,7 +1840,7 @@ test_vglongnames(void)
status = Vgetclassnamelen(vg1, &name_len);
CHECK_VOID(status, FAIL, "Vgetnamelen");

vgclass = (char *)malloc(sizeof(char *) * (name_len + 1));
vgclass = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(vgclass, "vgclass", "test_vglongnames");

status = Vgetclass(vg1, vgclass);
Expand All @@ -1867,7 +1867,7 @@ test_vglongnames(void)
status = Vgetnamelen(vg1, &name_len);
CHECK_VOID(status, FAIL, "Vgetnamelen");

vgname = (char *)malloc(sizeof(char *) * (name_len + 1));
vgname = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(vgname, "vgname", "test_vglongnames");

status = Vgetname(vg1, vgname);
Expand All @@ -1884,7 +1884,7 @@ test_vglongnames(void)
status = Vgetclassnamelen(vg1, &name_len);
CHECK_VOID(status, FAIL, "Vgetnamelen");

vgclass = (char *)malloc(sizeof(char *) * (name_len + 1));
vgclass = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(vgclass, "vgclass", "test_vglongnames");

status = Vgetclass(vg1, vgclass);
Expand Down Expand Up @@ -2749,7 +2749,7 @@ test_extfile(void)
name_len = VSgetexternalfile(vdata1_id, 0, NULL, NULL);
VERIFY_VOID(name_len, (intn)strlen(EXTERNAL_FILE), "VSgetexternalfile");

extfile_name = (char *)malloc(sizeof(char *) * (name_len + 1));
extfile_name = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(extfile_name, "extfile_name", "test_extfile");

/* Old function: Get the external file name - VSgetexternalfile
Expand All @@ -2764,7 +2764,7 @@ test_extfile(void)
name_len = VSgetexternalinfo(vdata1_id, 0, NULL, NULL, NULL);
VERIFY_VOID(name_len, (intn)strlen(EXTERNAL_FILE), "VSgetexternalinfo");

extfile_name = (char *)malloc(sizeof(char *) * (name_len + 1));
extfile_name = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(extfile_name, "extfile_name", "test_extfile");

/* Get the external file name */
Expand All @@ -2777,13 +2777,13 @@ test_extfile(void)
name should be truncated */
{
/* Make a shorter string to verify later */
char *short_name = (char *)malloc(sizeof(char *) * (name_len));
char *short_name = (char *)malloc(sizeof(char) * (name_len));
memset(short_name, '\0', name_len);
strncpy(short_name, EXTERNAL_FILE, name_len - 2);

/* Prepare buffer for external file name in the following test */
extfile_name = (char *)malloc(sizeof(char *) * (name_len - 1));
memset(extfile_name, '\0', name_len);
extfile_name = (char *)malloc(sizeof(char) * (name_len - 1));
memset(extfile_name, '\0', name_len - 1);

/* Call VSgetexternalinfo again with smaller buffer size and make sure
VSgetexternalinfo reads the name truncated to the given buffer size*/
Expand Down
Loading