What does SDL_GetError say in the case of an error? - c

My main question: Please may you list a few examples of what SDL_GetError would print?
I want to use SDL_GetError to help me debug, however I don't know what to expect or how to create my own intentional errors.
The libsdl wiki says:
The message is only applicable when an SDL function has signaled an
error. You must check the return values of SDL function calls to determine
when to appropriately call SDL_GetError().
however http://sdl.beuc.net/sdl.wiki/SDL_GetError says:
Although this example uses SDL_Init, SDL_GetError provides an error
message for any failed SDL operation.
so which is it? Only some or all? None of the SDL wikis/documentations I have seen give a list of example error messages, so I don't know how to initiate an error, or what to expect in terms of content and format. Is
Error in `./foo': double free or corruption (top):
an SDL_GetError message or is that caused by something else?

The wiki entry for SDL_Error lists the error strings:
SDL_errorcode | The corresponding error string
SDL_ENOMEM | Out of memory
SDL_EFREAD | Error reading from datastream
SDL_EFWRITE | Error writing to datastream
SDL_EFSEEK | Error seeking in datastream
SDL_UNSUPPORTED | Unknown SDL error
SDL_LASTERROR | Unknown SDL error
any other value | Unknown SDL error
See also SDL_error.c. One of the wiki entries seems to be incorrect. The correct error code - error string pair would be:
SDL_UNSUPPORTED | That operation is not supported
You can set custom errors messages with SDL_SetError - see the .c above. Finally, "double free or corruption" is not an error caused by SDL, but most likely by a double free. I suggest gdb/valgrind to debug it.

Related

How to abort a macports portfile on an error condition?

I working on a version bump on the cc65 and encountered a problem with the linuxdoc-tools. Since I can't fix the linuxdoc-tools and there is a simple workaround possible I decided to add an if statement to inform the user together with the workaround:
if {! [file exists ${prefix}/bin/perl] } {
ui_error "
«${prefix}/bin/perl» is missing but the linuxdoc-tools depends on it.
Please create an appropriate symbolic link for linuxdoc-tools to work.
"
exit 1
}
Crude but the best I can do since I'm neither the perl5 nor the linuxdoc-tools maintainer and I don't want to spend to much time on a version bump.
However, the MacPorts doesn't understand exit 1 and ui_error won't stop execution on its own.
How do I stop the execution so not to waste the users time on a build which will otherwise fail right at the end.
Use return -code error "error message", or the shorthand for the same thing, error "error message".
Note that you should use ui_error before that to print a human-readable message for the user – while the error message is also being printed, it can sometimes get lost in the output.
Additionally, note that $prefix/bin/perl is a build dependency of linuxdoc-tools. If it is also needed at runtime, you should submit a pull request that adds depends_run path:bin/perl:perl5 to the port rather than attempting to fix this bug in your port.

How to Fix Format String bug

A practical example of the bug "in action" is the following:
Attacker sends: /hello-%08x.%08x.%08x.%08x
Server logs:
[17:17:28] Consoled: 'hello-082aeefc.00000131.0061b64c.00000011' run
from 192.168.0.3:32768
Update:
The bug is caused by the logging function NetManager_LogMessage which
takes the text to dump, adds a timestamp (using snprintf) and then
passes the whole string to the function File_printf without the needed
format argument (%s) and how to fix it?
What i have done wrong and why its happening?
I debug in IDA and when i test to Crash the Server. It returns the Memory Invalid access error.

Suppress messages from underlying C-function in R

In a script I often call the function Rcplex(), which prints "CPLEX environment opened" and "Closed CPLEX environment" to the console. Since the function is called rather frequently, it prints this very often, which is quite annoying. Is there a way to suppress this? I tried sink(), suppressWarnings/Messages or invisible(catch.output()) but none of these did the trick. I proceeded to check the code of Rcplex() and found where the printing to the console happens. Rcplex() calls an underlying C-function (Rcplex.c). In the code of rcplex.c I located the commands which cause the printing:
REprintf("CPLEX environment opened\n");
REprintf("Closed CPLEX environment\n");
Is there a way to capture the output from REprintf() so that it does not get printed to the R-console? One way would obviously be to mess around with the Rcplex.c file and delete the corresponding lines. However, this would not be a very clean solution, which is why I'm asking for another way to capture the output from C-functions.
You had problems using sink() and capture.output() normally because sink() does not redirect output from REprintf, as we see in comments from the source code for REprintf:
/* =========
* Printing:
* =========
*
* All printing in R is done via the functions Rprintf and REprintf
* or their (v) versions Rvprintf and REvprintf.
* These routines work exactly like (v)printf(3). Rprintf writes to
* ``standard output''. It is redirected by the sink() function,
* and is suitable for ordinary output. REprintf writes to
* ``standard error'' and is useful for error messages and warnings.
* It is not redirected by sink().
However, we can use type = "message" to deal with this; from help("capture.output"):
Messages sent to stderr() (including those from message, warning and
stop) are captured by type = "message". Note that this can be "unsafe" and should only be used with care.
First I make a C++ function with the same behavior you're dealing with:
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector example_function(NumericVector x) {
REprintf("CPLEX environment opened\n");
REprintf("Closed CPLEX environment\n");
// As mentioned by Dirk Eddelbuettel in the comments,
// Rcpp::Rcerr goes into the same REprintf() stream:
Rcerr << "Some more stuff\n";
return x;
}
If I call it from R normally, I get:
example_function(42)
CPLEX environment opened
Closed CPLEX environment
Some more stuff
[1] 42
However, I could instead do this:
invisible(capture.output(example_function(42), type = "message"))
[1] 42
And while the output is is printed to the console, the message is not.
Warning
I would be remiss if I didn't mention the warning from the help file I quoted above:
Note that this can be "unsafe" and should only be used with care.
The reason is that this will eliminate all output from actual errors as well. Consider the following:
> log("A")
Error in log("A") : non-numeric argument to mathematical function
> invisible(capture.output(log("A"), type = "message"))
>
You may or may not want to therefore send the captured output to a text file in case you have to diagnose something that went wrong. For example:
invisible(capture.output(log("A"), type = "message", file = "example.txt"))
Then I don't have to see the message in the console, but if I need to check example.txt afterward, the message is there:
Error in log("A") : non-numeric argument to mathematical function

why this error appears "all scheduled cores encountered errors in user code" is it related to core processor of servers?

We are analyzing sequencing data while filtering and trimming fastq files encountered following error. Is the following error due to unavailability of core for processing commands?
Error in colnames<-(*tmp*, value = c("cs103_R1_dada.fastq", "cs110_R1_dada.fastq", : attempt to set 'colnames' on an object with less than two dimensions In addition: Warning message: In mclapply(seq_len(n), do_one, mc.preschedule = mc.preschedule, : all scheduled cores encountered errors in user code >
As pengchy suggested there may be something wrong with function.
try the same call by using lapply and error message will be more informative.
To clarify on what #f2003596 and #HelloWorld said: This just means that a crash occurred within the function you called, i.e. while it was executing that function. But this does not necessarily mean that your function is incorrect. For example, you get the same error when a variable has not been found.
That would mean your R function has a crash.
Note: If you include an unexpected argument in mclapply you also can get this error message. I put mC.cores instead of mc.cores by mistake and I got it.

fio error checking for write operations

I am trying to determine how fio (github.com/axboe/fio) determines if there is a write error when using the libaio ioengine.
From the post at linux kernel aio functionality, I see an example of error checking in the callback function, work_done(), which examines the events returned by io_getevents().
But I cannot find any similar error checking in the fio_libaio_getevents() function from libaio.c (https://github.com/axboe/fio/blob/master/engines/libaio.c#L145).
I have written to the mailing list (fio#vger.kernel.org) from https://github.com/axboe/fio/blob/fio-2.17/README#L77, but the mail bounces. So any help would be much appreciated.
Thanks in advance.
The errors are returned as res and res2 in struct iocb. In that fio code, you can see the iocb array passed in here, as ld->aio_events + events.
r = io_getevents(ld->aio_ctx, actual_min,
max, ld->aio_events + events, lt);
The actual error is checked earlier in the file, in the function fio_libaio_event.

Resources