changeset 12678:e4374feb2e3f octave-forge

[nan-tb] fix bug when file open fails; address several compiler warnings
author schloegl
date Thu, 20 Aug 2015 09:01:53 +0000
parents e083820799fe
children a74726ba86d1
files extra/NaN/src/xptopen.cpp
diffstat 1 files changed, 6 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/extra/NaN/src/xptopen.cpp	Mon Aug 17 17:10:27 2015 +0000
+++ b/extra/NaN/src/xptopen.cpp	Thu Aug 20 09:01:53 2015 +0000
@@ -301,7 +301,7 @@
 	}
 
 	fid = fopen(fn,Mode);
-	if (fid < 0) {
+	if (fid == NULL) {
 	        mexErrMsgTxt("Can not open file!\n");
 		}
 
@@ -372,7 +372,7 @@
 				}
 
 				if (rec_type != 2) 
-					;//error('invalid SPSS file');
+					mexErrMsgTxt("invalid SPSS file\n");
 
 				c2 += fread(VarNames+9*ns,1,8,fid);
 				VarNames[9*ns+8] = 0;
@@ -469,8 +469,8 @@
 			char typ; int32_t len;
 			char flagSWAP = (((__BYTE_ORDER == __BIG_ENDIAN) && LittleEndian) || ((__BYTE_ORDER == __LITTLE_ENDIAN) && !LittleEndian));
 			do {
-				fread(&typ,1,1,fid);
-				fread(&len,4,1,fid);
+				if (!fread(&typ,1,1,fid)) break;
+				if (!fread(&len,4,1,fid)) break;
 				if (flagSWAP) bswap_32(len);
 				fseek(fid,len,SEEK_CUR);
 			} while (len);
@@ -724,7 +724,7 @@
 						else if (vartyp[ns] == 6) {
 							size_t kk[6],n=0, N=strlen(datestr[ns]);
 							char T0[6][5];
-							char ix = 0;
+							int ix = 0;
 							struct tm t;
 
 							for (n=0; n < N; n++) {
@@ -1092,7 +1092,7 @@
 	mexPrintf("d2xpt(%f)\n",x);
 #endif
 	// see http://old.nabble.com/Re%3A-IBM-integer-and-double-formats-p20428979.html
-	m = *(uint64_t*) &x;
+	memcpy(&m, &x, 8);
 	*(((char*)&m) + 6) &= 0x0f; //
 	if (e) *(((char*)&m) + 6) |= 0x10; // reconstruct implicit leading '1' for normalized numbers
 	m <<= (3-(-e & 3));