<p>In <a href="https://github.com/geany/geany/pull/621#discussion_r40608720">src/document.c</a>:</p>
<pre style='color:#555'>>      {
>            ui_set_statusbar(TRUE, "%s", err->message);
>            g_error_free(err);
>            return FALSE;
>    }
>  
> -  filedata->len = (gsize) st.st_size;
</pre>
<p><a href="https://github.com/b4n" class="user-mention">@b4n</a> Maybe I miss something but right now (without my patch):</p>

<ol>
<li>The stat() length value is passed to encodings_convert_to_utf8_auto() here</li>
</ol>

<p><a href="https://github.com/geany/geany/blob/master/src/document.c#L963">https://github.com/geany/geany/blob/master/src/document.c#L963</a></p>

<ol>
<li>encodings_convert_to_utf8_auto() stores this value to buffer.size and strlen() to buffer.len parameter passed to handle_buffer() here:</li>
</ol>

<p><a href="https://github.com/geany/geany/blob/master/src/encodings.c#L1082">https://github.com/geany/geany/blob/master/src/encodings.c#L1082</a></p>

<ol>
<li>Finally, handle_buffer() compares these two and does some magic based on this:</li>
</ol>

<p><a href="https://github.com/geany/geany/blob/master/src/encodings.c#L1029">https://github.com/geany/geany/blob/master/src/encodings.c#L1029</a></p>

<p>The thing is we need both the stat() value and strlen() value in order to do what's done in (3). Right now, my patch discards the stat() value which causes that the buffer->len != buffer->size check is equivalent to FALSE.</p>

<p>In the commit I mentioned the size was just moved into encodings.c but the two values are still there.</p>

<p>So I think this is something that should be fixed in my patch - personally I'd move the stat call inside handle_buffer() because passing the size value from somewhere else is a bit misleading (I at least assumed it was the size of the string which isn't the case).</p>

<p>What do you think?</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br>Reply to this email directly or <a href="https://github.com/geany/geany/pull/621/files#r40608720">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/ABDrJz4HS_tO64Cbtj-6t_tnBNki0jRwks5o2aofgaJpZM4FwLm6.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/geany/geany/pull/621/files#r40608720"></link>
  <meta itemprop="name" content="View Pull Request"></meta>
</div>
<meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>