gnuastro-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[task #16114] Print warning where integer overflow happens


From: Mohammad Akhlaghi
Subject: [task #16114] Print warning where integer overflow happens
Date: Mon, 24 Apr 2023 19:14:53 -0400 (EDT)

Update of task #16114 (project gnuastro):

        Percent Complete:                      0% => 80%                    

    _______________________________________________________

Follow-up Comment #11:

Thanks a lot for the nice commit Siyang, being able to read through all those
layers of macros and editing/adding the necessary components was not trivial!

I was able to compile the branch successfully. To test it, I added the
following line after the variable definitions of 'arithmetic_operator_run' in
'bin/arithmetic/arithmetic.c' (to activate overflow checking):


flags|=GAL_ARITHMETIC_FLAG_OVERFLOW_CHECK;


After running the following command (using 'tests/during-dev.sh'), I was able
to see the warning message:


$ astarithmetic 200 100 u8 + --quiet
Overflow. Operation: +. Type: uint8_t. Left: 200. Right: 100. Max: 255. Min:
0. 
44


Here are some comments:
* For printing warnings, it is much better to use the
[https://www.gnu.org/software/libc/manual/html_node/Error-Messages.html
'error()' function] (with 'EXIT_SUCCESS' as its first argument). If you search
for 'EXIT_SUCCESS' in Gnuastro's source, you will see many instances. The
reason is that 'error()' also prints the name of the calling program (which is
necessary when the user sees the warning in the output of a script with many
programs). It also has some other very useful features that follow basic
standards. Don't worry about portability, since Gnuastro uses the
[https://www.gnu.org/software/gnulib GNU portability library], this function
will work in Gnuastro's source even for those non-GNU operating systems that
don't have 'error()'.
* You can't break the error message with 'error()' into in multiple calls like
you do with 'fprintf'. To fix this, all the separate
'COMPOSE_OVERFLOW_ERR_MSG' calls can write a string (using 'asprintf' for
example) and you can put the call of 'error()' at the end of the function and
print the string in the same call ;-).
* The main thing that slightly worried me was the compilation time. Have you
investigated how to speed up the compilation? For the user it doesn't really
matter (since they only compile once), but during developing, it becomes
important. 
* I have sent you the copyright form to fill and submit. Hopefully by the time
that is done, we will also make progress on the points above and we can merge
it into the 'master' branch ;-).


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/task/?16114>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]