Quick question: is this code security-sensitive at all?<div><br></div><div>I know that there has been some security issues related to one compiler (Microsoft's) that was optimizing away the memset in some cases. So the suggested workaround was a loop. Reference: Writing Secure Code.</div>
<div><br></div><div>The other question is: Are we still supporting building with such a compiler? My bad memory tells me that VS 2008 and later should not have this behavior anymore, but it is worthwhile to double-check.<br>
<br>On Tuesday, January 8, 2013, Stephan Bergmann  wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 12/24/2012 06:44 PM, Julien Nabet wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 24/12/2012 18:29, Norbert Thiebaud wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Mon, Dec 24, 2012 at 8:45 AM, julien2412<<a>serval2412@yahoo.fr</a>>  wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
By taking a look at the file  sal/typesconfig/typesconfig.c,<br>
GetAlignment<br>
function, I wonder if we could replace the for loop by a memset to<br>
optimize<br>
a bit.<br>
So here's a straightforward patch:<br>
diff --git a/sal/typesconfig/typesconfig.<u></u>c<br>
b/sal/typesconfig/typesconfig.<u></u>c<br>
index 473f07a..ef52c5f 100644<br>
--- a/sal/typesconfig/typesconfig.<u></u>c<br>
+++ b/sal/typesconfig/typesconfig.<u></u>c<br>
@@ -262,11 +262,9 @@ int GetAlignment( Type eT )<br>
  {<br>
    char  a[ 16*8 ];<br>
    long  p = (long)(void*)a;<br>
-  int   i;<br>
<br>
    /* clear a[...] to set legal value for double access */<br>
-  for ( i = 0; i<  16*8; i++ )<br>
-    a[i] = 0;<br>
+  memset(a, 0, sizeof(a));<br>
<br>
    p = ( p + 0xF )&  ~0xF;<br>
    for ( i = 1; i<  16; i++ )<br>
<br>
Would it be ok?<br>
</blockquote>
well you can't remove<br>
  int i;<br>
<br>
since it is still used in the second for loop.<br>
<br>
and I doubt that that code is run very often... namely 4 times per<br>
execution of the typesconfig executable... which in turn run dozens of<br>
fprintf...<br>
I'd say that this micro-optimization would be completely<br>
un-measurable, and may or may not be an optimization at all depending<br>
on how the memset is treated.<br>
but sure, it is 'ok', as in it won't hurt anything.<br>
</blockquote></blockquote>
<br>
The benefit of memset over an explicit loop here would be shorter, more obvious (IMO) code, so I'd suggest you do the change after all.<br>
<br>
Stephan<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
ok let's forget it, I suppose that the one who made this loop has<br>
certainly good reasons for this + you must be right, micro-optimization<br>
</blockquote>
______________________________<u></u>_________________<br>
LibreOffice mailing list<br>
<a>LibreOffice@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/libreoffice" target="_blank">http://lists.freedesktop.org/<u></u>mailman/listinfo/libreoffice</a><br>
</blockquote></div><br><br>-- <br>Marc-André LAVERDIÈRE<br>"Perseverance must finish its work so that you may be mature and complete, <br>not lacking anything." -James 1:4<br><a href="http://asimplediscipleslife.blogspot.com/">http://asimplediscipleslife.blogspot.com/</a><br>
<a href="http://mlaverd.theunixplace.com">mlaverd.theunixplace.com</a><br><br><br>