bug 11411: save function used unsigned char to store length of string, now it is... 54/8554/3
Antoine ELIAS [Mon, 6 Aug 2012 09:02:58 +0000 (11:02 +0200)]
Change-Id: I4cbce565b150e34b6fe8110efe609b025f3db692

scilab/CHANGES_5.4.X
scilab/modules/fileio/macros/%_listvarinfile.sci
scilab/modules/graphics/macros/%h_load.sci
scilab/modules/graphics/macros/%h_save.sci
scilab/modules/graphics/tests/nonreg_tests/bug_11411.dia.ref [new file with mode: 0644]
scilab/modules/graphics/tests/nonreg_tests/bug_11411.tst [new file with mode: 0644]

index 25dbed8..dace9f0 100644 (file)
@@ -28,6 +28,9 @@ Bug Fixes
 * Bug #8151 fixed - Under Mac OS X, item "Scilab/Quit Scilab" and "File/Quit" were
                     duplicates.
 
+* Bug #11411 fixed - save function used unsigned char to store length of string.
+                     Now it is an integer.
+
 * Bug #11509 fixed - A progression bar was missing during Atoms operations.
 
 * Bug #11592 fixed - In the documentation, example of bessel failed.
index 7d99c53..87f9b47 100644 (file)
@@ -263,12 +263,20 @@ function totalSize = getSingleHandleInfo(fd, totalSize)
             totalSize = seekShortCount(fd, 2, totalSize); //axes_size
             if is_higher_than( [4 1 2 0] ) then
                 totalSize = seekShortCount(fd, 2, totalSize); //viewport
-                totalSize = seekString(fd, totalSize); // info_message
+                if is_higher_than([5 4 0 0]) then
+                    totalSize = seekStringInt(fd, totalSize); // info_message
+                else
+                    totalSize = seekString(fd, totalSize); // info_message
+                end
                 totalSize = seekString(fd, totalSize); // tag
             end
 
             totalSize = seekBool(fd, totalSize); // auto_resize
-            totalSize = seekString(fd, totalSize); // figure_name
+            if is_higher_than([5 4 0 0]) then
+                totalSize = seekStringInt(fd, totalSize); // figure_name
+            else
+                totalSize = seekString(fd, totalSize); // figure_name
+            end
             totalSize = seekShort(fd, totalSize); //figure_id
             totalSize = seekMatrix(fd, totalSize); // color_map
             totalSize = seekBool(fd, totalSize); // pixmap
@@ -793,7 +801,7 @@ function totalSize = getSingleHandleInfo(fd, totalSize)
                 totalSize = seekInt(fd, totalSize); // background
             end
 
-            if (is_higher_than([5 0 3 0])) then
+            if is_higher_than([5 0 3 0]) then
                 totalSize = seekMatrix(fd, totalSize); // data
             else
                 global parentAxesView;
@@ -1023,7 +1031,11 @@ function totalSize = getSingleHandleInfo(fd, totalSize)
                 totalSize = seekMatrix(fd, totalSize); // Foregroundcolor
                 totalSize = seekString(fd, totalSize); // Label
                 totalSize = seekBool(fd, totalSize); // Visible
-                totalSize = seekString(fd, totalSize); // Callback
+                if is_higher_than([5 4 0 0]) then
+                    totalSize = seekStringInt(fd, totalSize); // Callback
+                else
+                    totalSize = seekString(fd, totalSize); // Callback
+                end
                 totalSize = seekInt(fd, totalSize); // Callback Type
                 totalSize = seekString(fd, totalSize); // Tag
             end
@@ -1070,7 +1082,11 @@ function totalSize = getSingleHandleInfo(fd, totalSize)
                 totalSize = seekMatrix(fd, totalSize); // Value
                 totalSize = seekString(fd, totalSize); // VerticalAlignment
                 totalSize = seekBool(fd, totalSize); // Visible
-                totalSize = seekString(fd, totalSize); // Callback
+                if is_higher_than([5 4 0 0]) then
+                    totalSize = seekStringInt(fd, totalSize); // Callback
+                else
+                    totalSize = seekString(fd, totalSize); // Callback
+                end
                 totalSize = seekInt(fd, totalSize); // Callback Type
                 totalSize = seekUserdata(fd, totalSize); // Userdata
                 totalSize = seekString(fd, totalSize); // Tag
@@ -1241,7 +1257,11 @@ function newSize = seekStringMatrix(fd, currentSize)
     row = mget(1, "il", fd);
     col = mget(1, "il", fd);
     for i = 1 : row * col
-        currentSize = seekString(fd, currentSize); // String
+        if is_higher_than([5 4 0 0])
+            currentSize = seekStringInt(fd, currentSize); // String
+        else
+            currentSize = seekString(fd, currentSize); // String
+        end
     end
     newSize = currentSize + 4 * 2;
 endfunction
index de6730b..b5a94fd 100644 (file)
@@ -15,9 +15,9 @@ function h=%h_load(fd)
   init_immediate_drawing = 0;
 
   version=mget(4,'uc',fd)
-
   // saving/loading character with 'c' is actually quite buggy
   characterFormat = 'uc';
+  stringFormat = 'il';
 
   immediate_drawing="";
 
@@ -68,11 +68,19 @@ function [h,immediate_drawing] = load_graphichandle(fd)
       axes_size=mget(2,'sl',fd); //axes_size
       if ( is_higher_than([4 1 2 0]) ) then
         viewport = mget(2,'sl',fd) ; // viewport
-        info_message = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) ; // info_message
+        if is_higher_than([5 4 0 0]) then
+            info_message = ascii(mget(mget(1,stringFormat,fd),characterFormat,fd)) ; // info_message
+        else
+            info_message = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) ; // info_message
+        end
         tag = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) ; // tag
       end
       auto_resize=toggle(mget(1,characterFormat,fd)); // auto_resize
-      figure_name=ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) // figure_name
+      if is_higher_than([5 4 0 0]) then
+          figure_name=ascii(mget(mget(1,stringFormat,fd),characterFormat,fd)) // figure_name
+      else
+          figure_name=ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) // figure_name
+      end
       figure_id=mget(1,'sl',fd); // figure_id
       h.color_map=matrix(mget(mget(1,'il',fd),"dl",fd),-1,3) // color_map
       pixmap=toggle(mget(1,characterFormat,fd)); // pixmap
@@ -93,11 +101,19 @@ function [h,immediate_drawing] = load_graphichandle(fd)
       axes_size=mget(2,'sl',fd); // axes_size
       if ( is_higher_than([4 1 2 0]) ) then
         viewport = mget(2,'sl',fd) ; // viewport
-        info_message = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) ; // info_message
+        if is_higher_than([5 4 0 0]) then
+            info_message = ascii(mget(mget(1,stringFormat,fd),characterFormat,fd)) ; // info_message
+        else
+            info_message = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) ; // info_message
+        end
         tag = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) ; // tag
       end
       auto_resize=toggle(mget(1,characterFormat,fd)); // auto_resize
-      figure_name=ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) // figure_name
+      if is_higher_than([5 4 0 0]) then
+          figure_name=ascii(mget(mget(1,stringFormat,fd),characterFormat,fd)) // figure_name
+      else
+          figure_name=ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) // figure_name
+      end
       figure_id=mget(1,'sl',fd); // figure_id
       // create the figure
       h=scf(figure_id);
@@ -1374,7 +1390,11 @@ function [h,immediate_drawing] = load_graphichandle(fd)
       h.foregroundcolor = mget(ncolors,"dl",fd); // ForegroundColor (data)
       h.label = ascii(mget(mget(1,"c",fd),"c",fd)); // Label
       h.visible = toggle(mget(1,"c",fd)); // Visible
-      h.callback = ascii(mget(mget(1,"c",fd),"c",fd)); // Callback
+      if is_higher_than( [5 4 0 0] ) then
+        h.callback = ascii(mget(mget(1, stringFormat,fd),"c",fd)); // Callback
+      else
+        h.callback = ascii(mget(mget(1,"c",fd),"c",fd)); // Callback
+      end
       h.callback_type = mget(1,"il",fd); // Callback Type
       h.tag = ascii(mget(mget(1,"c",fd),"c",fd)); // Tag
     end
@@ -1434,7 +1454,11 @@ function [h,immediate_drawing] = load_graphichandle(fd)
       h.value = mget(ndata,"dl",fd); // Value (data)
       h.verticalalignment = ascii(mget(mget(1,"c",fd),"c",fd)); // VerticalAlignment
       h.visible = toggle(mget(1,"c",fd)); // Visible
-      h.callback = ascii(mget(mget(1,"c",fd),"c",fd)); // Callback
+      if is_higher_than( [5 4 0 0] ) then
+        h.callback = ascii(mget(mget(1, stringFormat,fd),"c",fd)); // Callback
+      else
+        h.callback = ascii(mget(mget(1,"c",fd),"c",fd)); // Callback
+      end
       h.callback_type = mget(1,"il",fd); // Callback Type
       load_user_data(fd); // Userdata
       h.tag = ascii(mget(mget(1,"c",fd),"c",fd)); // Tag
@@ -1487,7 +1511,11 @@ function strMat = load_text_matrix( fd )
   nbCol = mget( 1, 'il', fd ) ;
   for i = 1:nbRow
     for j = 1:nbCol
-      strMat(i,j) = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) ;
+      if is_higher_than([5 4 0 0]) then
+        strMat(i,j) = ascii(mget(mget(1,stringFormat,fd),characterFormat,fd)) ;
+      else
+        strMat(i,j) = ascii(mget(mget(1,characterFormat,fd),characterFormat,fd)) ;
+      end
     end
   end
 endfunction
index ecfc35c..8d6743f 100644 (file)
 
 
 function %h_save(h,fd)
-  version=[5 4 0 0]
+  version=[5 4 0 1]
   mput(version,'uc',fd)
   
   // There are issues when saving characters with 'c' format
   // characterFormat format behave smoothly
   characterFormat = 'uc';
+  stringFormat = 'il';
   
   hsize = size(h);
   mput(hsize,characterFormat,fd); 
@@ -49,12 +50,12 @@ function save_graphichandle(h,fd)
     mput(h.figure_size,'sl',fd) // figure size
     mput(h.axes_size,'sl',fd) // axes_size
     mput(h.viewport,'sl',fd) // viewport
-    mput(length(ascii(h.info_message)),characterFormat,fd) ; // info_message
+    mput(length(ascii(h.info_message)),stringFormat,fd) ; // info_message
     mput(ascii(h.info_message),characterFormat,fd) ;
     mput(length(ascii(h.tag)),characterFormat,fd) ; // tag
     mput(ascii(h.tag),characterFormat,fd) ;
     mput(bool2s(h.auto_resize=='on'),characterFormat,fd) // auto_resize
-    mput(length(ascii(h.figure_name)),characterFormat,fd); // figure_name
+    mput(length(ascii(h.figure_name)),stringFormat,fd); // figure_name
     mput(ascii(h.figure_name),characterFormat,fd);
     mput(h.figure_id,'sl',fd); // figure_id
     
@@ -625,7 +626,7 @@ function save_graphichandle(h,fd)
     mput(h.foregroundcolor,"dl",fd); // ForegroundColor (data)
     mput(length(h.label),"c",fd);mput(ascii(h.label),"c",fd); // Label
     mput(bool2s(h.visible=="on"),"c",fd); // Visible
-    mput(length(h.callback),"c",fd);mput(ascii(h.callback),"c",fd); // Callback
+    mput(length(h.callback),stringFormat,fd);mput(ascii(h.callback),"c",fd); // Callback
     mput(h.callback_type,"il",fd); // Callback Type
     mput(length(h.tag),"c",fd);mput(ascii(h.tag),"c",fd); // Tag
     mput(bool2s(h.checked=="on"),"c",fd); // Checked
@@ -677,7 +678,7 @@ function save_graphichandle(h,fd)
     mput(h.value,"dl",fd); // Value (data)
     mput(length(h.verticalalignment),"c",fd);mput(ascii(h.verticalalignment),"c",fd); // VerticalAlignment
     mput(bool2s(h.visible=="on"),"c",fd); // Visible
-    mput(length(h.callback),"c",fd);mput(ascii(h.callback),"c",fd); // Callback
+    mput(length(h.callback),stringFormat,fd);mput(ascii(h.callback),"c",fd); // Callback
     mput(h.callback_type,"il",fd); // Callback Type
     user_data=h.user_data;save(fd,user_data); // Userdata
     mput(length(h.tag),"c",fd);mput(ascii(h.tag),"c",fd); // Tag
@@ -702,7 +703,7 @@ function save_text_matrix(strMat,fd)
   mput( nbCol, 'il', fd ) ;
   for i = 1:nbRow
     for j = 1:nbCol
-      mput(length(ascii(strMat(i,j))),characterFormat,fd) ;
+      mput(length(ascii(strMat(i,j))), stringFormat, fd) ;
       mput(ascii(strMat(i,j)),characterFormat,fd) ;
     end
   end
diff --git a/scilab/modules/graphics/tests/nonreg_tests/bug_11411.dia.ref b/scilab/modules/graphics/tests/nonreg_tests/bug_11411.dia.ref
new file mode 100644 (file)
index 0000000..ad23784
--- /dev/null
@@ -0,0 +1,52 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - Scilab Enterprises - Antoine ELIAS
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- TEST WITH GRAPHIC -->
+//
+// <-- Non-regression test for bug 11411 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=11411
+//
+// <-- Short Description -->
+//  save function used unsigned char to store length of string, now it is an integer
+oldMode = warning('query');
+warning("off");
+longstring = strcat(mgetl("SCI/COPYING-BSD")); //1639
+//"figure".info_message
+//"figure".igure_name
+f = gcf();
+f.info_message = longstring;
+f.figure_name = longstring;
+save(TMPDIR + "/savef.dat", f);
+delete(f);
+clear f;
+load(TMPDIR + "/savef.dat");
+assert_checkequal(f.info_message, longstring);
+assert_checkequal(f.figure_name, longstring);
+delete(f);
+clear f;
+//"uimenu".callback
+m = uimenu(gcf(),'label', 'test', 'callback', longstring); //no sense, just for test !
+save(TMPDIR + "/savef.dat", m);
+delete(gcf());
+clear m;
+load(TMPDIR + "/savef.dat");
+assert_checkequal(m.callback, longstring);
+delete(gcf());
+clear m;
+//"uicontrol".String
+//"uicontrol".callback
+m = uicontrol(gcf(), "Style", "text", "string",longstring, "callback", longstring);
+save(TMPDIR + "/savef.dat", m);
+delete(gcf());
+clear m;
+load(TMPDIR + "/savef.dat");
+assert_checkequal(m.callback, longstring);
+assert_checkequal(m.string, longstring);
+delete(gcf());
+clear m;
+warning(oldMode);
diff --git a/scilab/modules/graphics/tests/nonreg_tests/bug_11411.tst b/scilab/modules/graphics/tests/nonreg_tests/bug_11411.tst
new file mode 100644 (file)
index 0000000..42a70fd
--- /dev/null
@@ -0,0 +1,57 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - Scilab Enterprises - Antoine ELIAS
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- TEST WITH GRAPHIC -->
+//
+// <-- Non-regression test for bug 11411 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=11411
+//
+// <-- Short Description -->
+//  save function used unsigned char to store length of string, now it is an integer
+
+oldMode = warning('query');
+warning("off");
+longstring = strcat(mgetl("SCI/COPYING-BSD")); //1639
+
+//"figure".info_message
+//"figure".igure_name
+f = gcf();
+f.info_message = longstring;
+f.figure_name = longstring;
+save(TMPDIR + "/savef.dat", f);
+delete(f);
+clear f;
+load(TMPDIR + "/savef.dat");
+assert_checkequal(f.info_message, longstring);
+assert_checkequal(f.figure_name, longstring);
+delete(f);
+clear f;
+
+//"uimenu".callback
+m = uimenu(gcf(),'label', 'test', 'callback', longstring); //no sense, just for test !
+save(TMPDIR + "/savef.dat", m);
+delete(gcf());
+clear m;
+load(TMPDIR + "/savef.dat");
+assert_checkequal(m.callback, longstring);
+delete(gcf());
+clear m;
+
+//"uicontrol".String
+//"uicontrol".callback
+m = uicontrol(gcf(), "Style", "text", "string",longstring, "callback", longstring);
+save(TMPDIR + "/savef.dat", m);
+delete(gcf());
+clear m;
+load(TMPDIR + "/savef.dat");
+assert_checkequal(m.callback, longstring);
+assert_checkequal(m.string, longstring);
+delete(gcf());
+clear m;
+warning(oldMode);
+