On Mon, 26 Dec 2011, Tim Bannister wrote:

+      sshc->readdir_totalLen += 4 + sshc->readdir_len;

     sshc->readdir_currLen += snprintf(sshc->readdir_line +
                                       sshc->readdir_currLen,

If this is the same ‘4’ as on line 1889:
     new_readdir_line = realloc(sshc->readdir_line,
                                sshc->readdir_totalLen + 4 +
                                sshc->readdir_len);

then would it make sense to assign this number once and then use the constant for both cases? It's more clear, I think.

Yes it is, and I think we can prevent the same addition to be used twice by simply doing it like this:

--- a/lib/ssh.c
+++ b/lib/ssh.c
@@ -1885,9 +1885,9 @@ static CURLcode ssh_statemach_act(struct connectdata *conn
       Curl_safefree(sshc->readdir_linkPath);
       sshc->readdir_linkPath = NULL;

-      new_readdir_line = realloc(sshc->readdir_line,
-                                 sshc->readdir_totalLen + 4 +
-                                 sshc->readdir_len);
+      /* get room for the filename and extra output */
+      sshc->readdir_totalLen += 4 + sshc->readdir_len:
+      new_readdir_line = realloc(sshc->readdir_line, sshc->readdir_totalLen);
       if(!new_readdir_line) {
         Curl_safefree(sshc->readdir_line);
         sshc->readdir_line = NULL;

Armel, won't this work just as good in your case?

--

 / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to