--- a\srcmatrixex\iupmatex_clipboard.c	Tue Jul 04 23:08:32 2017
+++ b\srcmatrixex\iupmatex_clipboard.c	Sat Jan 13 19:04:42 2018
@@ -668,11 +668,10 @@
 
 static int iMatrixExSetPasteFileAttrib(Ihandle *ih, const char* value)
 {
-  size_t size;
-  char* data, *paste_at;
-  int lin = 0, col = 0;
+  long size;
+  FILE *file;
 
-  FILE *file = fopen(value, "rb");
+  file = fopen(value, "rb");
   if (!file)
   {
     iupAttribSet(ih, "LASTERROR", "IUP_ERRORFILEOPEN");
@@ -680,32 +679,48 @@
   }
 
   fseek(file, 0, SEEK_END);
-  size = (size_t)ftell(file); 
-  fseek(file, 0, SEEK_SET);
-
-  data = (char*)malloc(size+1);
-  fread(data, size, 1, file);
-  data[size] = 0;
-  fclose(file);
-
-  paste_at = iupAttribGet(ih, "PASTEFILEAT");
-  if (paste_at)
+  size = ftell(file);
+  if (size != -1L)
   {
-    if (iupStrEqualNoCase(paste_at, "FOCUS"))
-      IupGetIntInt(ih, "FOCUSCELL", &lin, &col);
-    else
-    {
-      if (iupStrToIntInt(paste_at, &lin, &col, ':') != 2)
-      {
-        free(data);
+     long read_size;
+     char* data, *paste_at;
+     int lin = 0, col = 0;
+
+     data = (char*)malloc(size+1);
+     if (data == NULL)
+     {
+        fclose(file);
+        iupAttribSet(ih, "LASTERROR", "IUP_ERRORMALLOC");
         return 0;
-      }
-    }
+     }
+     fseek(file, 0, SEEK_SET);
+     read_size = fread(data, size, 1, file);
+     fclose(file);
+     data[read_size] = '\0';
+
+     paste_at = iupAttribGet(ih, "PASTEFILEAT");
+     if (paste_at)
+     {
+        if (iupStrEqualNoCase(paste_at, "FOCUS"))
+        {
+           IupGetIntInt(ih, "FOCUSCELL", &lin, &col);
+        }
+        else
+        {
+           if (iupStrToIntInt(paste_at, &lin, &col, ':') != 2)
+           {
+              free(data);
+              return 0;
+           }
+        }
+     }
+     iMatrixExPasteData(ih, data, lin, col, "PASTEFILE");
+     free(data);
+     return 1; /* 1 IS SUCESS? */
   }
+  fclose(file);
+  iupAttribSet(ih, "LASTERROR", "IUP_ERRORFILETELL");
 
-  iMatrixExPasteData(ih, data, lin, col, "PASTEFILE");
-
-  free(data);
   return 0;
 }
 
