<html>
    <head>
      <base href="https://bugs.freedesktop.org/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - OpenType weight between 0 and 100 could result in assertion in FcWeightFromOpenType"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=82228">82228</a>
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>fontconfig-bugs@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>OpenType weight between 0 and 100 could result in assertion in FcWeightFromOpenType
          </td>
        </tr>

        <tr>
          <th>QA Contact</th>
          <td>freedesktop@behdad.org
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>daphnediane@mac.com
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

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

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

        <tr>
          <th>Component</th>
          <td>library
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>fontconfig
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Calling FcWeightFromOpenType with ot_weight between 1 and 99 triggers an
assertion. lerp will get called with x = ot_weight, x1 = 0, x2 = 100, y1 = 0,
y2 = 0. It will then compute dy = y2 - y1 = 0. Which will cause assert ( dx > 0
&& dy > 0 && x1 <= x && x <= x2 ) to fail as dy is 0. Seems like if dy == 0,
then it should return y1.

Possible patch

diff --git a/src/fcweight.c b/src/fcweight.c
index 87bbe67..4def775 100644
--- a/src/fcweight.c
+++ b/src/fcweight.c
@@ -45,6 +45,7 @@ static int lerp(int x, int x1, int x2, int y1, int y2)
 {
   int dx = x2 - x1;
   int dy = y2 - y1;
+  if (dy == 0 && x1 <= x && x <= x2) return y1;
   assert (dx > 0 && dy > 0 && x1 <= x && x <= x2);
   return y1 + (dy*(x-x1) + dx/2) / dx;
 }</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>