Home | About | Amazon Store | Briefing | Investing | Links | Site Search | USX China | StockInsight* | Login | Register

RSS Feed for This PostCurrent Article

Dumb C++ Mistakes

It seems like I don’t have anything to do with C++ because I have not touched C++ much in this blog. I am a software engineer by trade; programming and debugging is a large part of what I do during the day. I was a little frustrated last two days by a memory problem shown only on UNIX. The program ran fine on Windows, except one or two instances slightly weird results which I tend to ignore. But I could not pass the UNIX test and obviously something is wrong. By looking at the trace back I can tell it’s a memory problem. Memory problem is kind of problem everyone hates. Because it’s usually hard to find the root cause. Dev Partner made the process a little easier because it will show all potential memory overrun and leaks. To my surprise, I made a mistake like the following (very basic C++ mistakes):

char *temp_str = new char[length]; 

for(int ii = 0; ii < length*2; ii++){

    // do something with temp_str[ii]

}

It is a typical memory overrun problem because I only allocate “length” number of char, but I was trying to use “length*2″ number of char. It’s like use twice the credit limit?

But I am still very puzzlled that my program ran on Windows (without Dev Parter) before the fix. No wonder we see “Windows crash” from time to time :-)

Seriously, in software development we want the problems being uncovered the earlier, the better. Because we don’t want our customer run our program and crash.

Trackback URL

Tags: ,
EMail This Post

Bookmark

Save to del.icio.us

Ads

Google
 
Web www.stlplace.com

RSS Feed for This PostPost a Comment

// 最新推荐 Noteworthy
  • John Bogle WSJ op-ed 01/08/2009: 6 Lessons for Investors
  • Buffett NY Times op-ed 10/17/2008: Buy American. I Am.
  • Buffett article Fortune 11/10/2001: Stock Market: What's in the future for investors
  • Berkshire 08 Meeting Q&A Transcript: html (GuruFocus), PDF
  • Google Ad

  • blog

  • China

  • finance

  • Links

  • Major

  • Pro (for ref only)

  • Saint Louis

  • Shanghai

  • Meta

  • Author作者

    "古人云,人不自信谁人信之." Others won't believe in you unless you believe yourself. --Chinese proverb

    Hello, world :-) I am not another stock expert. I am an ordinary guy who believes: by lifetime learning, indepenent analysis and disciplined investing, little guys can achieve great return.

    I grew up in China and currently working on CFA level I this June. Here I'm blogging about business, finance, stocks, other fun stuffs in the US and China. Comments and Email are welcome.

  • Disclaimer声明

    See Disclaimer Page
  • Valid XHTML 1.0 Transitional