Using CGraphic::Flip() on a 32-bit image causes a crash

Bug #1442716 reported by Andre Novellino Gouvêa
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Stratagus
Won't Fix
Undecided
Unassigned

Bug Description

Something is amiss with this piece of code in CGraphic::Flip(), which is causing a crash when the function is used on a 32-bit image:

  case 4: {
   unsigned int p0 = s->pitch;
   unsigned int p1 = Surface->pitch;
   const int width = s->w;
   int j = 0;
   for (int i = 0; i < s->h; ++i) {
#ifdef _MSC_VER
    for (j = 0; j < width; ++j) {
     *(Uint32 *)&((char *)s->pixels)[j * 4 + p0] =
      *(Uint32 *) & ((char *)Surface->pixels)[(width - j - 1) * 4 + p1];
    }
#else
    int n = (width + 7) / 8;
    switch (width & 7) {
     case 0: do {
       *(Uint32 *)&((char *)s->pixels)[j * 4 + p0] =
        *(Uint32 *) & ((char *)Surface->pixels)[(width - j - 1) * 4 + p1];
       j++;
      case 7:
       *(Uint32 *)&((char *)s->pixels)[j * 4 + p0] =
        *(Uint32 *) & ((char *)Surface->pixels)[(width - j - 1) * 4 + p1];
       j++;
      case 6:
       *(Uint32 *)&((char *)s->pixels)[j * 4 + p0] =
        *(Uint32 *) & ((char *)Surface->pixels)[(width - j - 1) * 4 + p1];
       j++;
      case 5:
       *(Uint32 *)&((char *)s->pixels)[j * 4 + p0] =
        *(Uint32 *) & ((char *)Surface->pixels)[(width - j - 1) * 4 + p1];
       j++;
      case 4:
       *(Uint32 *)&((char *)s->pixels)[j * 4 + p0] =
        *(Uint32 *) & ((char *)Surface->pixels)[(width - j - 1) * 4 + p1];
       j++;
      case 3:
       *(Uint32 *)&((char *)s->pixels)[j * 4 + p0] =
        *(Uint32 *) & ((char *)Surface->pixels)[(width - j - 1) * 4 + p1];
       j++;
      case 2:
       *(Uint32 *)&((char *)s->pixels)[j * 4 + p0] =
        *(Uint32 *) & ((char *)Surface->pixels)[(width - j - 1) * 4 + p1];
       j++;
      case 1:
       *(Uint32 *)&((char *)s->pixels)[j * 4 + p0] =
        *(Uint32 *) & ((char *)Surface->pixels)[(width - j - 1) * 4 + p1];
       j++;
      } while (--n > 0);
    }
#endif
    p0 += s->pitch;
    p1 += Surface->pitch;
   }
  }
  break;

Revision history for this message
timfelgentreff (timfelgentreff) wrote : Moving to GitHub

This project was moved to https://github.com/Wargus/stratagus. All issues were migrated there.

Changed in stratagus:
status: New → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.