Skip to content
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

sscanf() is broken (hangs / stores unexpected values) #16

Open
JayFoxRox opened this issue Dec 18, 2019 · 1 comment
Open

sscanf() is broken (hangs / stores unexpected values) #16

JayFoxRox opened this issue Dec 18, 2019 · 1 comment

Comments

@JayFoxRox
Copy link
Member

JayFoxRox commented Dec 18, 2019

This code (taken from Neverball) leads to faulty behaviour:

#ifdef NXDK
#include <hal/video.h>
#include <hal/debug.h>
#else
#define debugPrint(...) printf(__VA_ARGS__)
#endif
#include <stdio.h>

int main() {

#ifdef NXDK
  XVideoSetMode(640, 480, 32, REFRESH_DEFAULT);
#endif

  const char* line = "fullscreen                0";

  int ks, ke, vs;

  ks = -1;
  ke = -1;
  vs = -1;

  debugPrint("Starting scan\n");

  int ret = sscanf(line, " %n%*s%n %n", &ks, &ke, &vs);

  debugPrint("Result %d = %d %d %d\n", ret, ks, ke, vs);

#ifdef NXDK
  while(1);
#else
  return 0;
#endif
}

On my desktop with clang I get:

Starting scan
Result 0 = 0 10 26

On nxdk (in XQEMU) I only get:

Starting scan

(it seems to hang before the second debugPrint is reached)

On nxdk (in XQEMU) I got this with an older revision of the code which didn't retrieve / print int ret:

Starting scan
Result 1701995379 1819047270 10

Probably a bug in pdclib? CC @DevSolar

@JayFoxRox
Copy link
Member Author

This was fixed upstream in DevSolar#8.
I'm not sure if nxdk-pdclib has the fix yet.

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

Successfully merging a pull request may close this issue.

1 participant