[Monetr-users] r88 - pkg/MonetDB.R/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jul 23 16:39:46 CEST 2013


Author: hannes
Date: 2013-07-23 16:39:45 +0200 (Tue, 23 Jul 2013)
New Revision: 88

Modified:
   pkg/MonetDB.R/src/mapisplit.c
Log:
checking if malloc fails

Modified: pkg/MonetDB.R/src/mapisplit.c
===================================================================
--- pkg/MonetDB.R/src/mapisplit.c	2013-07-23 12:24:27 UTC (rev 87)
+++ pkg/MonetDB.R/src/mapisplit.c	2013-07-23 14:39:45 UTC (rev 88)
@@ -2,7 +2,9 @@
 #include <Rdefines.h>
 #include <assert.h>
 #include <string.h>
+#include <errno.h>
 
+
 typedef enum {
 	INQUOTES, ESCAPED, NORMAL
 } chrstate;
@@ -57,7 +59,9 @@
 				if (chr == ',' || curPos == linelen - 2) {
 					int tokenLen = curPos - tokenStart + 1 - endQuote;
 					char *valPtr = (char*) malloc(tokenLen * sizeof(char));
-
+					if (valPtr == NULL) {
+						printf("malloc() failed. Are you running out of memory? [%s]\n", strerror(errno));
+					}
 					strncpy(valPtr, val + tokenStart, tokenLen);
 					valPtr[tokenLen - 1] = '\0';
 					SEXP colV = VECTOR_ELT(colVec, cCol);
@@ -69,8 +73,6 @@
 						SET_STRING_ELT(colV, cRow, mkChar(valPtr));
 					}
 
-
-
 					free(valPtr);
 
 					cCol++;



More information about the Monetr-users mailing list