diff --git a/README.html b/README.html index d30b3a6..594da1e 100644 --- a/README.html +++ b/README.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- +stdint.h
Memory allocation of structures can be facilitated by using the @@ -374,8 +374,8 @@ object is the same as the size of the data type pointed by the pointer.
#define MALLOC(T) (T*) malloc (sizeof(T)); -#define CALLOC(N,T) (T*) calloc ((N),sizeof(T)); +#define MALLOC(T) (T*) malloc (sizeof(T)) +#define CALLOC(N,T) (T*) calloc ( (N) , sizeof(T) )
#define FREE(X) { free(X) ; (X)=NULL; }
+The maximum string size for the filenames is 4096 characters. +
+#define TREXIO_MAX_FILENAME_LENGTH 4096 ++
All calls to TREXIO are thread-safe. @@ -401,10 +408,10 @@ TREXIO front end is modular, which simplifies impelementation of new back ends.
The C
templates that correspond to each of the abovementioned functions can be found below.
@@ -1397,8 +1410,8 @@ The basic (non-suffixed) API call on dimensioning variables deals with single pr
The Fortran
templates that provide an access to the C
API calls from Fortran.
@@ -1485,8 +1498,8 @@ These templates are based on the use of iso_c_binding
. Pointers hav
This section concerns API calls related to datasets. @@ -1555,8 +1568,8 @@ This section concerns API calls related to datasets.
The C templates that correspond to each of the abovementioned functions can be found below. @@ -1814,8 +1827,8 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T
The Fortran
templates that provide an access to the C
API calls from Fortran
.
@@ -1902,8 +1915,8 @@ These templates are based on the use of iso_c_binding
. Pointers hav
The function below adapts the original C-based trexio_open
for Fortran.
@@ -1932,7 +1945,7 @@ Note, that Fortran interface calls the main TREXIO
API, which is wr
#define $GROUP$_GROUP_NAME "$group$" @@ -340,8 +340,8 @@ for the JavaScript code in this tag.
typedef struct trexio_hdf5_s { @@ -356,8 +356,8 @@ for the JavaScript code in this tag.
trexio_exit_code
@@ -440,8 +440,8 @@ for the JavaScript code in this tag.
trexio_exit_code
@@ -564,8 +564,8 @@ for the JavaScript code in this tag.
trexio_exit_code
@@ -696,7 +696,7 @@ for the JavaScript code in this tag.
$group_num$
attribute$group_dset$
dataset$group_num$
attribute$group_dset$
datasetThe "file" produced by the text back end is a directory with one @@ -359,8 +359,8 @@ The file is written when closed, or when the flush function is called.
typedef struct $group$_s { @@ -376,8 +376,8 @@ The file is written when closed, or when the flush function is called.
typedef struct rdm_s { @@ -403,8 +403,8 @@ The file is written when closed, or when the flush function is called.
trexio_exit_code @@ -434,15 +434,19 @@ The file is written when closed, or when the flush function is called. /* Create the lock file in the directory */ const char* lock_file_name = "/.lock"; - size_t str_size = strlen(file->file_name) + strlen(lock_file_name) + 1; - char* file_name = CALLOC(str_size, char); + char* file_name = CALLOC(TREXIO_MAX_FILENAME_LENGTH, char); if (file_name == NULL) { return TREXIO_ALLOCATION_FAILED; } - strncpy (file_name, file->file_name, str_size); - strncat (file_name, lock_file_name, strlen(lock_file_name)); + strncpy (file_name, file->file_name, TREXIO_MAX_FILENAME_LENGTH); + strncat (file_name, lock_file_name, TREXIO_MAX_FILENAME_LENGTH-strlen(lock_file_name)); + + if (file_name[TREXIO_MAX_FILENAME_LENGTH-1] != '\0') { + FREE(file_name); + return TREXIO_ALLOCATION_FAILED; + } f->lock_file = open(file_name,O_WRONLY|O_CREAT|O_TRUNC, 0644); FREE(file_name); @@ -507,8 +511,8 @@ The file is written when closed, or when the flush function is called.
trexio_exit_code
@@ -532,8 +536,8 @@ The file is written when closed, or when the flush function is called.
$group$_t* @@ -555,16 +559,22 @@ trexio_text_read_$group$ (trexio_text_t*Build the file name */ const char* $group$_file_name = "/$group$.txt"; - size_t str_size = strlen(file->parent.file_name) + strlen($group$_file_name) + 1; - char * file_name = CALLOC(str_size, char); + char * file_name = CALLOC(TREXIO_MAX_FILENAME_LENGTH, char); if (file_name == NULL) { FREE($group$); return NULL; } - strncpy (file_name, file->parent.file_name, str_size); - strncat (file_name, $group$_file_name, strlen($group$_file_name)); + strncpy (file_name, file->parent.file_name, TREXIO_MAX_FILENAME_LENGTH); + strncat (file_name, $group$_file_name, + TREXIO_MAX_FILENAME_LENGTH-strlen($group$_file_name)); + + if (file_name[TREXIO_MAX_FILENAME_LENGTH-1] != '\0') { + FREE(file_name); + FREE($group$); + return NULL; + } /* If the file exists, read it */ FILE* f = fopen(file_name,"r"); @@ -724,8 +734,8 @@ trexio_text_read_$group$ (trexio_text_t*
trexio_exit_code @@ -783,8 +793,8 @@ trexio_text_read_$group$ (trexio_text_t*
Memory is allocated when reading. The following function frees memory. @@ -825,8 +835,8 @@ Memory is allocated when reading. The following function frees memory.
$group_num$
attribute$group_num$
attributetrexio_exit_code
@@ -888,8 +898,8 @@ Memory is allocated when reading. The following function frees memory.
$group_dset$
dataset$group_dset$
dataset
The group_dset
array is assumed allocated with the appropriate size.
@@ -986,12 +996,12 @@ The group_dset
array is assumed allocated with the appropriate size
rdm_t* trexio_text_read_rdm(trexio_text_t* const file); @@ -1005,7 +1015,7 @@ Thegroup_dset
array is assumed allocated with the appropriate size if (file->rdm != NULL) return file->rdm; /* Allocate the data structure */ - rdm_t* const rdm = MALLOC(rdm_t); + rdm_t* rdm = MALLOC(rdm_t); assert (rdm != NULL); rdm->one_e = NULL; @@ -1015,13 +1025,19 @@ Thegroup_dset
array is assumed allocated with the appropriate size /* Try to open the file. If the file does not exist, return */ const char* rdm_file_name = "/rdm.txt"; - size_t str_size = strlen(file->parent.file_name) + strlen(rdm_file_name) + 1; - char * file_name = CALLOC(str_size, char); + char* file_name = CALLOC(TREXIO_MAX_FILENAME_LENGTH, char); assert (file_name != NULL); - strncpy (file_name, file->parent.file_name, str_size); - strncat (file_name, rdm_file_name, strlen(rdm_file_name)); + strncpy (file_name, file->parent.file_name, TREXIO_MAX_FILENAME_LENGTH); + strncat (file_name, rdm_file_name, + TREXIO_MAX_FILENAME_LENGTH-strlen(rdm_file_name)); + + if (file_name[TREXIO_MAX_FILENAME_LENGTH-1] != '\0') { + FREE(file_name); + FREE(rdm); + return NULL; + } /* If the file exists, read it */ FILE* f = fopen(file_name,"r"); if (f != NULL) { @@ -1063,9 +1079,17 @@ Thegroup_dset
array is assumed allocated with the appropriate size rc = fscanf(f, "%1023s", buffer); assert (rc == 1); - str_size = strlen(buffer); - rdm->two_e_file_name = CALLOC(str_size,char); - strncpy(rdm->two_e_file_name, buffer, str_size); + rdm->two_e_file_name = CALLOC(TREXIO_MAX_FILENAME_LENGTH,char); + strncpy(rdm->two_e_file_name, buffer, 1024); + if (rdm->two_e_file_name[TREXIO_MAX_FILENAME_LENGTH-1] != '\0') { + FREE(file_name); + FREE(buffer); + FREE(rdm->one_e); + FREE(rdm->two_e_file_name); + FREE(rdm); + fclose(f); + return NULL; + } FREE(buffer); fclose(f); @@ -1085,8 +1109,8 @@ Thegroup_dset
array is assumed allocated with the appropriate size
trexio_exit_code trexio_text_flush_rdm(trexio_text_t* const file);
@@ -1129,8 +1153,8 @@ The group_dset
array is assumed allocated with the appropriate size
Memory is allocated when reading. The followig function frees memory. @@ -1175,8 +1199,8 @@ Memory is allocated when reading. The followig function frees memory.
The one_e
array is assumed allocated with the appropriate size.
@@ -1242,8 +1266,8 @@ The one_e
array is assumed allocated with the appropriate size.
two_e
is a sparse data structure, which can be too large to fit
@@ -1351,7 +1375,7 @@ file for each sparse float structure.