What was the most dangerous programming mistake you have made in C?

前端 未结 26 1173
南方客
南方客 2021-02-03 12:46

I am an intermediate C programmer. If you have made any coding mistake that you came to know later that it was the most hazardous / harmful to the total application please share

相关标签:
26条回答
  • 2021-02-03 13:37

    Uninitialized data.

    0 讨论(0)
  • 2021-02-03 13:37

    I was dealing with dynamically allocated 2D arrays and I instead of free()'ing N rows, I decided to free M columns. This was fine for smaller inputs where N == M but on large inputs, I only free()'d 50% of what I allocated.

    shrug

    Live and learn.

    0 讨论(0)
  • 2021-02-03 13:38
    while(a)
    { 
       // code - where 'a' never reaches 0 :( 
    }
    
    0 讨论(0)
  • 2021-02-03 13:40

    It has been a long time, but some things you never forget ;-).

    • forget the \0 at the end of a string.
    • allocate n characters for a string with n characters.
    • forgetting the break in a switch statement.
    • 'creative' macro use.
    0 讨论(0)
  • 2021-02-03 13:40

    You should worry more about little mistakes. Big/spectacular mistakes are usually documented in books (with reasons why they are bad, alternative approaches etc.).

    It's the little design/coding mistakes that get to you, because they tend to add up.

    So my advice is to try and read the books Kernighan wrote or co-authored ("The C Programming Language", "Practice of Programming" etc.) because they are full of common-sense (common for experienced C programmers) advice and list principles that are very useful in avoiding both small and big mistakes.

    They also list many potential big mistakes, so they answer your initial question.

    0 讨论(0)
  • 2021-02-03 13:40

    Forgetting architecture constraints and happily memcpy()ing into the memory mapped I/O area on a microcontroller. The magic smoke was released from the test rig.

    0 讨论(0)
提交回复
热议问题