Ecore_X (RandR): Fix long outstanding randr bug which caused
authorChristopher Michael <cpmichael1@comcast.net>
Fri, 7 Sep 2012 13:12:30 +0000 (13:12 +0000)
committerChristopher Michael <cpmichael1@comcast.net>
Fri, 7 Sep 2012 13:12:30 +0000 (13:12 +0000)
ecore_x_randr to not work for pretty much everyone. Short version,
don't memcpy something potentially Larger into something Certainly
smaller. (read on for the details).

NB: This 'should' fix all the randr problems in ecore_x (tho I have
not tested Everything).

NB: Ok, here goes:
    XRRGetScreenResources returns a struct. Inside that struct is a
    list of RROutputs.

    RROutput is defined as (from randrproto.h):
      #define RROutput CARD32

    CARD32 is defined as (from X11/Xmd.h):
      # ifdef LONG64
        typedef unsigned long CARD64;
        typedef unsigned int CARD32;
      # else
        typedef unsigned long CARD32;
      # endif
    so CARD32 can change based on the system (32/64 bit).

    Ecore_X_Randr_Output is defined as (Ecore_X.h):
       typedef Ecore_X_ID Ecore_X_Randr_Output;
       (for reference: typedef unsigned int Ecore_X_ID)

    Double bonus points if you have already spotted the problem !! ;)

SVN revision: 76306

legacy/ecore/src/lib/ecore_x/xlib/ecore_x_randr_12.c

index 3be89ac..b839736 100644 (file)
@@ -642,10 +642,12 @@ ecore_x_randr_outputs_get(Ecore_X_Window root,
      {
         if ((ret = malloc(sizeof(Ecore_X_Randr_Output) * res->noutput)))
           {
-             memcpy(ret, res->outputs,
-                    (sizeof(Ecore_X_Randr_Output) * res->noutput));
-             if (num)
-               *num = res->noutput;
+             int i = 0;
+
+             if (num) *num = res->noutput;
+
+             for (i = 0; i < res->noutput; i++)
+               ret[i] = res->outputs[i];
           }
 
         if (res)