<html>
    <head>
      <base href="https://bugs.freedesktop.org/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - _cairo_surface_is_snapshot() return error result on armcc on RVDS/MDK"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=93281">93281</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>_cairo_surface_is_snapshot() return error result on armcc on RVDS/MDK
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>cairo
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>ARM
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>critical
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>image backend
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>chris@chris-wilson.co.uk
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>chenzunfeng@qq.com
          </td>
        </tr>

        <tr>
          <th>QA Contact</th>
          <td>cairo-bugs@cairographics.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>static inline cairo_bool_t
_cairo_surface_is_snapshot (cairo_surface_t *surface)
{
    return surface->backend->type ==
(cairo_surface_type_t)CAIRO_INTERNAL_SURFACE_TYPE_SNAPSHOT;
}

On some platforms or compilers, size of enumuration types may be refered to the
max value of them, to reduce the memory usage. Like armcc of RVDS/MDK.

The detail on the armcc:

All the enum values of cairo_surface_type_t are small than 255, so the variable
defined by cairo_surface_type_t only has 1 bytes on the memory stack, but
CAIRO_INTERNAL_SURFACE_TYPE_SNAPSHOT = 0x1000, so it has two bytes.

The code snippet from cairo-surface-snapshort-inline.h (above), comparation
between cairo_surface_type_t and cairo_internal_surface_type_t,
CAIRO_INTERNAL_SURFACE_TYPE_SNAPSHOT is casted to cairo_surface_type_t, the
value may be wrong. Because not every compiler treates enumuration type as int.

Because of this, image surface crashed on arm cpu which is not running any OS.

There are too many code snippets cast a enumuration type to another one, this
may be not a good idea. ARMCC of RVDS/MDK gave me too many warning about the
issue.

I think there are not many persons run cairo on the bear metal without OS, but
it it indeed a problem.

The fixed code snippet that I've done is below:

static inline cairo_bool_t
_cairo_surface_is_snapshot (cairo_surface_t *surface)
{
    return (int)surface->backend->type ==
(int)CAIRO_INTERNAL_SURFACE_TYPE_SNAPSHOT;
}</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the QA Contact for the bug.</li>
      </ul>
    </body>
</html>