Skip to main content
added 167 characters in body
Source Link
vnp
  • 57.3k
  • 4
  • 51
  • 140
  • Asserts are good in the test cases, but not in the actual code. First, in a release version they are no-ops, so the release doesn't check anything. Second, they result in a program termination, which is a bit drastic.

  • Interfaces are unclear. What is len? It may only represent the length of the character array (vs C string), i.e. you do not rely on a terminating 0, and this, in turn, annuls the claim that strErase is filling the end with null chars. If you do rely on a terminating 0, do not have len as a parameter, but calculate it.

  • Treating negative count is a somewhat unorthodox. Normally (if allowed at all) it means "count backwards", that is, erase a [startIndex + count, startIndex) range.

  • Asserts are good in the test cases, but not in the actual code. First, in a release version they are no-ops, so the release doesn't check anything. Second, they result in a program termination, which is a bit drastic.

  • Interfaces are unclear. What is len? It may only represent the length of the character array (vs C string), i.e. you do not rely on a terminating 0, and this, in turn, annuls the claim that strErase is filling the end with null chars. If you do rely on a terminating 0, do not have len as a parameter, but calculate it.

  • Asserts are good in the test cases, but not in the actual code. First, in a release version they are no-ops, so the release doesn't check anything. Second, they result in a program termination, which is a bit drastic.

  • Interfaces are unclear. What is len? It may only represent the length of the character array (vs C string), i.e. you do not rely on a terminating 0, and this, in turn, annuls the claim that strErase is filling the end with null chars. If you do rely on a terminating 0, do not have len as a parameter, but calculate it.

  • Treating negative count is a somewhat unorthodox. Normally (if allowed at all) it means "count backwards", that is, erase a [startIndex + count, startIndex) range.

Source Link
vnp
  • 57.3k
  • 4
  • 51
  • 140

  • Asserts are good in the test cases, but not in the actual code. First, in a release version they are no-ops, so the release doesn't check anything. Second, they result in a program termination, which is a bit drastic.

  • Interfaces are unclear. What is len? It may only represent the length of the character array (vs C string), i.e. you do not rely on a terminating 0, and this, in turn, annuls the claim that strErase is filling the end with null chars. If you do rely on a terminating 0, do not have len as a parameter, but calculate it.