Re: 0.17.4 Win32 paste bug and possible fix

"Ken Koehler" <[email protected]> Thu, 18 Apr 2013 15:37:51 -0400
Newsgroups gmane.comp.emulators.tn5250
Message-ID <[email protected]>
   Wow, we've been choking on that one for years.
   As soon as I can make the time I'll try it.
   Thanks!

   ------ Original Message ------
   Received: 03:29 PM EDT, 04/18/2013
   From: Buck Calabro <[email protected]>
   To: linux5250-Zwy7GipZuJhWk0Htik3J/[email protected]
   Subject: [LINUX5250] 0.17.4 Win32 paste bug and possible fix

     I love tn5250 and am grateful that we have a community of people who
     support it. I myself am barely able to walk through the code so I
     appreciate the list looking over my shoulder...

     I had a long standing bug whereby I would copy some long-ish SQL out of
     a Word document and paste it into my tn5250 session and the session
     would crash with a Windows message saying that tn5250.exe has stopped
     working. I could never put my finger on the exact circumstances, and it
     never bothered me that much until recently when I had to do a LOT of
     these.

     So I started digging. Got to win32_paste_text_selection and started
     putting in TN5250_LOG() statements. Too busy to learn gdb :-( I
     eventually narrowed the error down to the bottom, 'free(pNewBuf);'
     Which didn't make much sense to me unless something had inadvertently
     stepped on pNewBuf. I'm still not a C programmer despite several hours
     of looking at the code (ha!), but the only place it looks like this
     routine could possibly step on pNewBuf is up above, where it says 'just
     a precaution'.

     if (hBuf != NULL) {
     size = GlobalSize(hBuf);
     size++;
     TN5250_LOG (("Windows clipboard size %d\n", size));
     pNewBuf = malloc(size);
     pBuf = GlobalLock(hBuf);
     strncpy(pNewBuf, pBuf, size);
     pNewBuf[size] = '\0'; /* just a precaution */
     GlobalUnlock(hBuf);
     }

     I added the line to increment size and my paste problem has gone away.
     Take it out, and it returns.

     I hope this makes sense.
     --buck
     --
     This is the Linux 5250 Development Project (LINUX5250) mailing list
     To post a message email: LINUX5250-Zwy7GipZuJhWk0Htik3J/[email protected]
     To subscribe, unsubscribe, or change list options,
     visit: http://lists.midrange.com/mailman/listinfo/linux5250
     or email: LINUX5250-request-Zwy7GipZuJhWk0Htik3J/[email protected]
     Before posting, please take a moment to review the archives
     at http://archive.midrange.com/linux5250.
-- 
This is the Linux 5250 Development Project (LINUX5250) mailing list
To post a message email: LINUX5250-Zwy7GipZuJhWk0Htik3J/[email protected]
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/linux5250
or email: LINUX5250-request-Zwy7GipZuJhWk0Htik3J/[email protected]
Before posting, please take a moment to review the archives
at http://archive.midrange.com/linux5250.