-
Notifications
You must be signed in to change notification settings - Fork 931
Replace sprintf with snprintf #13468
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
Merged
+83
−80
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4673f07
Replace sprintf with snprintf
devreal 2b56685
acoll: remove unused module variables
devreal 4bfe98e
comm_cid: initialize remote_cid64
devreal ef93ff4
comm_cid: fix printf warnings
devreal 588ae90
reduce-local: add parans around min/max macro
devreal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -325,9 +325,9 @@ abbreviate_list_into_string(char *str, int max, int *list, int nlist) | |
| strcpy(&str[strlen(str)], ", "); | ||
| } | ||
| if (lo != hi) { | ||
| sprintf(&str[strlen(str)], "%d - %d", lo, hi); | ||
| snprintf(&str[strlen(str)], max - strlen(str), "%d - %d", lo, hi); | ||
| } else { | ||
| sprintf(&str[strlen(str)], "%d", lo); | ||
| snprintf(&str[strlen(str)], max - strlen(str), "%d", lo); | ||
| } | ||
| } | ||
| /* | ||
|
|
@@ -352,9 +352,9 @@ abbreviate_list_into_string(char *str, int max, int *list, int nlist) | |
| strcpy(&str[strlen(str)], ", "); | ||
| } | ||
| if (lo != hi) { | ||
| sprintf(&str[strlen(str)], "%d - %d", lo, hi); | ||
| snprintf(&str[strlen(str)], max - strlen(str), "%d - %d", lo, hi); | ||
| } else { | ||
| sprintf(&str[strlen(str)], "%d", lo); | ||
| snprintf(&str[strlen(str)], max - strlen(str), "%d", lo); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -460,7 +460,7 @@ ompi_report_comm_methods(int called_from_location) | |
|
|
||
| len = strlen(opal_process_info.nodename) + 100; | ||
| hoststring = malloc(len + 1); | ||
| sprintf(hoststring, "Host %d [%s] ranks ", | ||
| snprintf(hoststring, len + 1, "Host %d [%s] ranks ", | ||
| myleaderrank, opal_process_info.nodename); | ||
|
|
||
| abbreviate_list_into_string(&hoststring[strlen(hoststring)], | ||
|
|
@@ -548,7 +548,7 @@ ompi_report_comm_methods(int called_from_location) | |
| ompi_count_array_t lens_desc; | ||
| ompi_disp_array_t disps_desc; | ||
|
|
||
| // First get the array of host strings (host names and task lists) | ||
| // First get the array of host strings (host names and task lists) | ||
| // for all nodes. | ||
| len = strlen(hoststring) + 1; | ||
| if (myleaderrank == 0) { | ||
|
|
@@ -642,7 +642,7 @@ ompi_report_comm_methods(int called_from_location) | |
| // 2: 2d table | ||
| if (nleaderranks <= max2Dprottable) { | ||
| char *str, *p; | ||
| int tmp, per, has_ucx_transport; | ||
| int tmp, per, has_ucx_transport, bufsize; | ||
| int strlens[NUM_COMM_METHODS]; | ||
|
|
||
| // characters per entry in the 2d table, must be large enough | ||
|
|
@@ -668,11 +668,11 @@ ompi_report_comm_methods(int called_from_location) | |
| if (tmp+1 > per) { per = tmp+1; } | ||
| } | ||
| } | ||
|
|
||
| str = malloc(nleaderranks * per + 1); | ||
| bufsize = nleaderranks * per + 1; | ||
| str = malloc(bufsize); | ||
| p = str; | ||
| for (i=0; i<nleaderranks; ++i) { | ||
| sprintf(p, "%d", i); | ||
| snprintf(p, bufsize - (p - str), "%d", i); | ||
| for (j=(int)strlen(p); j<per; ++j) { | ||
| p[j] = ' '; | ||
| } | ||
|
|
@@ -698,12 +698,12 @@ ompi_report_comm_methods(int called_from_location) | |
| for (k=0; k<nleaderranks; ++k) { | ||
| char *method_string; | ||
| char ucx_label[20]; | ||
|
|
||
| method_string = comm_method_to_string(method[i * nleaderranks + k]); | ||
| if (0 == strncmp(method_string, UCX_TAG, strlen(UCX_TAG))) { | ||
| n = lookup_string_in_conversion_struct(&comm_method_string_conversion, | ||
| method_string); | ||
| sprintf(ucx_label, "ucx[%3d]", n); | ||
| snprintf(ucx_label, sizeof(ucx_label), "ucx[%3d]", n); | ||
| strcat(p, ucx_label); | ||
| methods_used[n / 8] |= (1 << (n % 8)); | ||
| has_ucx_transport = 1; | ||
|
|
@@ -755,7 +755,7 @@ ompi_report_comm_methods(int called_from_location) | |
| } | ||
| else if (nleaderranks <= max2D1Cprottable) { | ||
| char *str, *p; | ||
| int tmp, per, done; | ||
| int tmp, per, done, bufsize; | ||
| char char_code[NUM_COMM_METHODS], next_char; | ||
| int method_count[NUM_COMM_METHODS]; | ||
|
|
||
|
|
@@ -798,12 +798,13 @@ ompi_report_comm_methods(int called_from_location) | |
| } | ||
| } | ||
|
|
||
| str = malloc(per + 32 + nleaderranks * 2 + 1); | ||
| bufsize = per + 32 + nleaderranks * 2 + 1; | ||
| str = malloc(bufsize); | ||
| p = str; | ||
| sprintf(p, "0 1 2 3 "); | ||
| snprintf(p, bufsize, "0 1 2 3 "); | ||
| p += 8; | ||
| for (i=4; i<nleaderranks; i+=4) { | ||
| sprintf(p, "%d", i); | ||
| snprintf(p, bufsize - (p - str), "%d", i); | ||
| for (j=(int)strlen(p); j<8; ++j) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trying to understand the memory allocation above I got totally confused by this piece of code. Why is j looping up to 8 instead of up to |
||
| p[j] = ' '; | ||
| } | ||
|
|
@@ -972,15 +973,16 @@ ompi_report_comm_methods(int called_from_location) | |
| } | ||
| } | ||
| if (is_nonconformist) { | ||
| char *str = malloc(1024); | ||
| // int first = 1; | ||
| sprintf(str, " host %d:", i); | ||
| const size_t bufsize = 1024; | ||
| char *str = malloc(bufsize); | ||
| snprintf(str, bufsize, " host %d:", i); | ||
| for (k=0; k<NUM_COMM_METHODS; ++k) { | ||
| if (method_count[k] > 0) { | ||
| // if (!first) { | ||
| // strcat(str, " /"); | ||
| // } | ||
| sprintf(&str[strlen(str)], | ||
| snprintf(&str[strlen(str)], | ||
| 1024 - strlen(str), | ||
| " [%dx %s]", | ||
| method_count[k], | ||
| comm_method_to_string(k)); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.