Comment bugged _priv->fp malloc and fix malloc of easycsv *csv in easycsv_init

This commit is contained in:
Pradana AUMARS 2021-06-29 23:33:34 +02:00
parent b2f9953f31
commit a8480a2fcf
1 changed files with 4 additions and 4 deletions

View File

@ -201,7 +201,7 @@ easycsv_init_errormsg(const char *fp,
csv->start = clock(); csv->start = clock();
#endif #endif
easycsv *csv = malloc(sizeof(csv)); easycsv *csv = malloc(sizeof(easycsv));
csv->mode = mode; csv->mode = mode;
csv->_priv = _easycsv_priv_init(fp, mode, error); csv->_priv = _easycsv_priv_init(fp, mode, error);
@ -728,9 +728,9 @@ _easycsv_priv_init(const char *fp,
size_t stfp = strlen(fp); size_t stfp = strlen(fp);
/* Allocate memory for char* */ /* Allocate memory for char* */
_priv->fp = malloc(stfp + 1); // + 1 for null // priv->fp = malloc(stfp + 1); // + 1 for null
strncpy(_priv->fp, fp, stfp); // strncpy(_priv->fp, fp, stfp);
/* Calculate rows and cols if file exists */ /* Calculate rows and cols if file exists */
if (access(_priv->fp, F_OK) == 0) { if (access(_priv->fp, F_OK) == 0) {
@ -901,7 +901,7 @@ _easycsv_columns(_easycsv *_priv,
3. if >1 column, n commas = n+1 columns 3. if >1 column, n commas = n+1 columns
*/ */
unsigned int col = 1; int col = 1;
char c; char c;
while ((c = fgetc(_priv->file)) != '\n') { while ((c = fgetc(_priv->file)) != '\n') {