Skip to content

addition to the "Troubleshooting your solution" page #519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Summer-the-coder
Copy link

from my experience, ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x000000000000 can also happen when an attempt to divide by zero is made, so I added it as a possible cause of this error.

@hobovsky
Copy link
Contributor

hobovsky commented Jun 13, 2025

Can you try and reproduce a division by zero error in some kumite or kata and double check that it results in "SEGV on unknown address 0x000000000000"? I remember seeing crashes due to division by zero sometimes, but they usually were FPE rather than segmentation fault? Maybe it would be worth to mention segmentation fault FPE in C and C++?

@Summer-the-coder
Copy link
Author

Summer-the-coder commented Jun 13, 2025

Yes (it's FPE instead of SEGV, but it's still "undefined behavior sanitizer"):

#include <cmath>

bool isPrime(int n) {
  if (n < 2) { return false; }
  if (n < 4) { return true; }
  if (n % 2 == 0 || n % 3 == 0) { return false; }
  int stopAt = ((int) std::sqrt(n)) + 1;

  // normally `i` would be 5 here
  for (int i = 0; i < stopAt; i += 6) {
    if (n % i == 0 || n % (i + 2) == 0) {
      return false;
    }
  }
  
  return true;
}

Run this code in this kata: https://www.codewars.com/kata/5262119038c0985a5b00029f/cpp.

@hobovsky
Copy link
Contributor

I am trying to figure out a way to organize this section nicely, because errors causing SEGV are something different than FPE and I think they look strange placed both under a section which is titled as SEGV.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants