--- a\srcmatrixex\iupmatex_clipboard.c	Tue Jul 04 23:08:32 2017
+++ b\srcmatrixex\iupmatex_clipboard.c	Sat Jan 13 19:15:17 2018
@@ -666,46 +666,62 @@
   return 0;
 }
 
-static int iMatrixExSetPasteFileAttrib(Ihandle *ih, const char* value)
+static int iMatrixExSetPasteFileAttrib(Ihandle *ih, const char* filename)
 {
-  size_t size;
-  char* data, *paste_at;
+  long size;
+  FILE *fp;
+  char *paste_at;
   int lin = 0, col = 0;
 
-  FILE *file = fopen(value, "rb");
-  if (!file)
+  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)
+        {
+           return 0;
+        }
+     }
+  }
+
+  fp = fopen(filename, "rb");
+  if (!fp)
   {
     iupAttribSet(ih, "LASTERROR", "IUP_ERRORFILEOPEN");
     return 0;
   }
 
-  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)
+  fseek(fp, 0, SEEK_END);
+  size = ftell(fp);
+  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;
+
+     data = (char *) malloc(size+1);
+     if (data == NULL)
+     {
+        fclose(fp);
+        iupAttribSet(ih, "LASTERROR", "IUP_ERRORMALLOC");
         return 0;
-      }
-    }
+     }
+     fseek(fp, 0, SEEK_SET);
+     read_size = fread(data, size, 1, fp);
+     fclose(fp);
+     data[read_size] = '\0';
+
+     iMatrixExPasteData(ih, data, lin, col, "PASTEFILE");
+     free(data);
+     return 1; /* 1 IS SUCESS? */
   }
+  fclose(fp);
+  iupAttribSet(ih, "LASTERROR", "IUP_ERRORFILETELL");
 
-  iMatrixExPasteData(ih, data, lin, col, "PASTEFILE");
-
-  free(data);
   return 0;
 }
 
