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

Replace asprintf with snprintf #7

Merged
merged 1 commit into from
Nov 28, 2023
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ config/ltversion.m4
config/lt~obsolete.m4
config/missing
configure
config/pmishim_get_version.sh~
configure~
libtool
Makefile
config.status
Expand Down
9 changes: 7 additions & 2 deletions src/pmi1.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <stdlib.h>
#endif

#include <stdio.h>

#define ANL_MAPPING "PMI_process_mapping"

#define PMI_MAX_ID_LEN PMIX_MAX_NSLEN /* Maximim size of PMI process group ID */
Expand Down Expand Up @@ -697,7 +699,7 @@ PMISHIM_EXPORT int PMI_Spawn_multiple(int count,
pmix_status_t rc = PMIX_SUCCESS;
pmix_app_t *apps;
int i, k;
size_t j;
size_t j, len;
char *evar;

PMI_CHECK();
Expand Down Expand Up @@ -728,11 +730,14 @@ PMISHIM_EXPORT int PMI_Spawn_multiple(int count,
}
/* push the preput values into the apps environ */
for (k = 0; k < preput_keyval_size; k++) {
if (0 > asprintf(&evar, "%s=%s", preput_keyval_vector[k].key, preput_keyval_vector[k].val)) {
len = strlen(preput_keyval_vector[k].key) + strlen(preput_keyval_vector[k].val) + 2;
evar = malloc(len);
if (0 > snprintf(evar, len, "%s=%s", preput_keyval_vector[k].key, preput_keyval_vector[k].val)) {
for (i = 0; i < count; i++) {
PMIX_APP_DESTRUCT(&apps[i]);
}
free(apps);
free(evar);
return PMIX_ERR_NOMEM;
}
PMIx_Argv_append_nosize(&apps[i].env, evar);
Expand Down
11 changes: 8 additions & 3 deletions src/pmi2.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <stdio.h>

#include "include/pmi2.h"
#include "pmix.h"
Expand Down Expand Up @@ -54,6 +55,7 @@ PMISHIM_EXPORT int PMI2_Init(int *spawned, int *size, int *rank, int *appnum)
pmix_proc_t proc = myproc;
proc.rank = PMIX_RANK_WILDCARD;

fprintf(stderr, "PMI2_INIT\n");
if (PMIX_SUCCESS != (rc = PMIx_Init(&myproc, NULL, 0))) {
/* if we didn't see a PMIx server (e.g., missing envar),
* then allow us to run as a singleton */
Expand Down Expand Up @@ -201,7 +203,7 @@ PMISHIM_EXPORT int PMI2_Job_Spawn(int count, const char * cmds[],
pmix_status_t rc = PMIX_SUCCESS;
pmix_app_t *apps;
int i, k;
size_t j;
size_t j, len;
char *evar;

PMI2_CHECK();
Expand Down Expand Up @@ -230,14 +232,17 @@ PMISHIM_EXPORT int PMI2_Job_Spawn(int count, const char * cmds[],
}
/* push the preput values into the apps environ */
for (k=0; k < preput_keyval_size; k++) {
if (0 > asprintf(&evar, "%s=%s", preput_keyval_vector[j].key, preput_keyval_vector[j].val)) {
len = strlen(preput_keyval_vector[j].key) + strlen(preput_keyval_vector[j].val) + 2;
evar = malloc(len);
if (0 > snprintf(evar, len, "%s=%s", preput_keyval_vector[j].key, preput_keyval_vector[j].val)) {
for (i = 0; i < count; i++) {
PMIX_APP_DESTRUCT(&apps[i]);
}
free(apps);
free(evar);
return PMIX_ERR_NOMEM;
}
pmix_argv_append_nosize(&apps[i].env, evar);
PMIx_Argv_append_nosize(&apps[i].env, evar);
free(evar);
}
}
Expand Down