summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/H5FDfamily.c33
-rw-r--r--src/H5FDsplitter.c33
2 files changed, 34 insertions, 32 deletions
diff --git a/src/H5FDfamily.c b/src/H5FDfamily.c
index 3f43ae9..323909f 100644
--- a/src/H5FDfamily.c
+++ b/src/H5FDfamily.c
@@ -234,27 +234,28 @@ H5FD__family_get_default_printf_filename(const char *old_filename)
HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, NULL, "can't allocate new filename buffer");
/* Determine if filename contains a ".h5" extension. */
- if ((file_extension = strstr(old_filename, ".h5"))) {
+ file_extension = strstr(old_filename, ".h5");
+ if (file_extension) {
/* Insert the printf format between the filename and ".h5" extension. */
- strcpy(tmp_buffer, old_filename);
- file_extension = strstr(tmp_buffer, ".h5");
- sprintf(file_extension, "%s%s", suffix, ".h5");
+ intptr_t beginningLength = file_extension - old_filename;
+ snprintf(tmp_buffer, new_filename_len, "%.*s%s%s", (int)beginningLength, old_filename, suffix, ".h5");
}
- else if ((file_extension = strrchr(old_filename, '.'))) {
- char *new_extension_loc = NULL;
-
+ else {
/* If the filename doesn't contain a ".h5" extension, but contains
* AN extension, just insert the printf format before that extension.
*/
- strcpy(tmp_buffer, old_filename);
- new_extension_loc = strrchr(tmp_buffer, '.');
- sprintf(new_extension_loc, "%s%s", suffix, file_extension);
- }
- else {
- /* If the filename doesn't contain an extension at all, just insert
- * the printf format at the end of the filename.
- */
- snprintf(tmp_buffer, new_filename_len, "%s%s", old_filename, suffix);
+ file_extension = strrchr(old_filename, '.');
+ if (file_extension) {
+ intptr_t beginningLength = file_extension - old_filename;
+ snprintf(tmp_buffer, new_filename_len, "%.*s%s%s", (int)beginningLength, old_filename, suffix,
+ file_extension);
+ }
+ else {
+ /* If the filename doesn't contain an extension at all, just insert
+ * the printf format at the end of the filename.
+ */
+ snprintf(tmp_buffer, new_filename_len, "%s%s", old_filename, suffix);
+ }
}
ret_value = tmp_buffer;
diff --git a/src/H5FDsplitter.c b/src/H5FDsplitter.c
index 723b191..56b2cdb 100644
--- a/src/H5FDsplitter.c
+++ b/src/H5FDsplitter.c
@@ -532,27 +532,28 @@ H5FD__splitter_get_default_wo_path(char *new_path, size_t new_path_len, const ch
HGOTO_ERROR(H5E_VFL, H5E_CANTSET, FAIL, "filename exceeds max length");
/* Determine if filename contains a ".h5" extension. */
- if ((file_extension = strstr(base_filename, ".h5"))) {
+ file_extension = strstr(base_filename, ".h5");
+ if (file_extension) {
/* Insert the suffix between the filename and ".h5" extension. */
- strcpy(new_path, base_filename);
- file_extension = strstr(new_path, ".h5");
- sprintf(file_extension, "%s%s", suffix, ".h5");
+ intptr_t beginningLength = file_extension - base_filename;
+ snprintf(new_path, new_path_len, "%.*s%s%s", (int)beginningLength, base_filename, suffix, ".h5");
}
- else if ((file_extension = strrchr(base_filename, '.'))) {
- char *new_extension_loc = NULL;
-
+ else {
/* If the filename doesn't contain a ".h5" extension, but contains
* AN extension, just insert the suffix before that extension.
*/
- strcpy(new_path, base_filename);
- new_extension_loc = strrchr(new_path, '.');
- sprintf(new_extension_loc, "%s%s", suffix, file_extension);
- }
- else {
- /* If the filename doesn't contain an extension at all, just insert
- * the suffix at the end of the filename.
- */
- snprintf(new_path, new_path_len, "%s%s", base_filename, suffix);
+ file_extension = strrchr(base_filename, '.');
+ if (file_extension) {
+ intptr_t beginningLength = file_extension - base_filename;
+ snprintf(new_path, new_path_len, "%.*s%s%s", (int)beginningLength, base_filename, suffix,
+ file_extension);
+ }
+ else {
+ /* If the filename doesn't contain an extension at all, just insert
+ * the suffix at the end of the filename.
+ */
+ snprintf(new_path, new_path_len, "%s%s", base_filename, suffix);
+ }
}
done: