Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Room for improvement?


  • Please log in to reply
No replies to this topic

#1 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:02:37 PM

Posted 30 December 2008 - 11:17 AM

Hello all :thumbsup:

Was working on a project and found myself needing a find and replace function that could handle both 64bit and 32 bit architectures, didn't require running on a class, and would be buffer-overrun safe.

Any improvements I could make to this code?
http://pastebin.com/f2de1695b

Billy3

EDIT: Already found a problem LOL

if (replacementDifference)
						_tcscpy(currentReplacement + replacementLen, currentReplacement + lookForLen);

Can't use strcpy() on the same array. Replaced that with memmove();
memmove(currentReplacement + replacementLen, currentReplacement + lookForLen, sizeof(TCHAR)*(_tcslen(currentReplacement) + 1) );

Edited by Billy O'Neal, 30 December 2008 - 11:32 AM.

Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

BC AdBot (Login to Remove)

 





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users