<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<meta content="text/html; charset=US-ASCII" http-equiv="Content-Type">
<title>
GitLab
</title>


<style>img {
max-width: 100%; height: auto;
}
</style>
</head>
<body>
<div class="content">

<p style="color: #777777;">
<a href="https://gitlab.com/karlson2k">Evgeny Grin</a>
<a href="https://gitlab.com/gnutls/gnutls/-/merge_requests/1377#note_509565944">commented</a>:
</p>
<div style="">
<p dir="auto"><a href="https://gitlab.com/dueno" data-user="470892" data-reference-type="user" data-container="body" data-placement="top" class="gfm gfm-project_member js-user-link" title="Daiki Ueno">@dueno</a> Thanks. Let me know how to improve it.</p>
<p dir="auto">There are several thing must be handled in this function:</p>
<ol dir="auto">
<li>The size of each element must be less than <code>ULONG_MAX</code> (actually max value for <code>DWORD</code>). If any element with larger size if found, is must be truncated to ULONG_MAX and no more element must be processed.</li>
<li>GnuTLS cannot process successful return value more than <code>SSIZE_MAX</code>, so amount of total sent size must be limited to <code>SSIZE_MAX</code>.</li>
</ol>
<p dir="auto">The code is so complicated because <code>ssize_t</code> is variable depending of x32/x64, but size of DWORD is fixed on Win32.
To handle both x32 and x64 in uniformed way, code needs to be a bit complicated.</p>
<p dir="auto">We can shield the second <code>if</code> like:</p>
<pre class="code highlight js-syntax-highlight plaintext" lang="plaintext" v-pre="true"><code><span id="LC1" class="line" lang="plaintext">#if SIZE_MAX > ULONG_MAX</span>
<span id="LC2" class="line" lang="plaintext">               else if (iovec[to_send_cnt].iov_len > ULONG_MAX) {</span>
<span id="LC3" class="line" lang="plaintext">                       bufs[to_send_cnt].buf = iovec[to_send_cnt].iov_base;</span>
<span id="LC4" class="line" lang="plaintext">                       bufs[to_send_cnt].len = ULONG_MAX;</span>
<span id="LC5" class="line" lang="plaintext">                       ovrflwn = true;</span>
<span id="LC6" class="line" lang="plaintext">               }</span>
<span id="LC7" class="line" lang="plaintext">#endif</span></code></pre>
<p dir="auto">but it will not make code more readable.</p>
</div>


</div>
<div class="footer" style="margin-top: 10px;">
<p style="font-size: small; color: #666;">

<br>
Reply to this email directly or <a href="https://gitlab.com/gnutls/gnutls/-/merge_requests/1377#note_509565944">view it on GitLab</a>.
<br>
You're receiving this email because of your account on gitlab.com.
If you'd like to receive fewer emails, you can
<a href="https://gitlab.com/-/sent_notifications/41353c2c8146c8ca2a3edc2b7be43583/unsubscribe">unsubscribe</a>
from this thread or
adjust your notification settings.
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Merge request","url":"https://gitlab.com/gnutls/gnutls/-/merge_requests/1377#note_509565944"}}</script>


</p>
</div>
</body>
</html>