Code Monkey home page Code Monkey logo

Comments (2)

ManuTester avatar ManuTester commented on August 27, 2024 2

This is a bug. isalpha and isdigit take an int, but they expect a value of 0..255 (or EOF) and not -128..127
One is supposed to cast a char into unsigned char before putting it into isalpha and the like. This was not fatal before, because -128...-1 are neither alphas nor digits so the function returned 0 for numbers < 0 anyway (EOF may be -1).
But now nano libraries seem to leave out the EOF support and just use the value as index to an array, which can be pretty bad with negative numbers.
If you do a man isalpha, you will see the NOTES:
NOTES
The standards require that the argument c for these functions is either EOF or a value that is representable in the type unsigned char. If the argument c is of type char, it must be cast
to unsigned char, as in the following example:

       char c;
       ...
       res = toupper((unsigned char) c);

   This is necessary because char may be the equivalent of signed char, in which case a byte where the top bit is set would be sign extended when converting to int, yielding a value  that  is
   outside the range of unsigned char.

   The details of what characters belong to which class depend on the locale.  For example, isupper() will not recognize an A-umlaut (Ä) as an uppercase letter in the default C locale.

from tinyexpr.

codeplea avatar codeplea commented on August 27, 2024

Thanks for the detailed explanation. I will try to fix this in the next update.

from tinyexpr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.