Showing posts with label error. Show all posts
Showing posts with label error. Show all posts

Saturday, February 26, 2011

My name is Antivirus. I hate Robots.

I have a confession to make - I’m using an antivirus on my Windows 7 computer. This word may seem unfamiliar to some Linux users who claim they don’t need it, and to some Windows users who claim that these stuff are viruses themselves. It never did any trouble, and it did save me several times, but today it was just an annoyance.

I was programming a game for the course I took in Computer Graphics. When I ran it, it exited before the first line of code and I got the following series of warnings:

The error messages

My first cynical thought was “Great! I programmed a virus!”. My brother’s reaction was “Wow – your code sucks so much that an antivirus recognized it as dangerous”. So, I rebuilt the executable (after the antivirus kindly removed it for me :P) and then I tried to scan it. The result was “No threats found”. I got the result for all the libraries and files used by my program.

After scanning lead to a dead end, I tried to comment out my code and remain with a simple hello world program (which still loads the same DLL’s) – and I still got the error message.

So then I tried to google for help about this error in my antivirus and I found out that it’s generated by a dynamic protection mechanism, which unlike traditional antiviruses, does not check the signature of my files.

So, what on earth was going on? An “Hello World” program which does nothing was causing a problem because of it’s dynamic behavior, while other programs which used the same libraries were OK? That does not make any sense.

Took me 30 minutes to figure this out:

  • The theme of the game was robots. Since it was the Visual Studio version, the logical name for the executable was VSrobots.exe.
  • The word robot is often used for describing certain types of viruses and malware.
  • The only difference between this program and others which used the library, was it’s name.

So, I renamed the executable “HelloWorld.exe” and a miracle happened – it ran perfectly without any warnings from the antivirus.

Conclusion: Don’t name your executable files after things which may sound like viruses. Otherwise ****** Antivirus will block them :P

Note: I didn’t mention the name of the antivirus, to save some troubles that may raise because of it (mainly flame wars and other similar stuff regarding which antivirus is better – I have seen many wars like this in the web). Therefore, please refrain from posting the name of the antivirus in the comments, even if you recognize these dialog boxes.

Thursday, October 21, 2010

Fixing errors with NAN (C const) and GCC

Today, I was compiling GEGL on a computer other than my regular one, and I got this wonderful error:
exp-combine.c: In function 'gegl_expcombine_new_exposure':
exp-combine.c:149: error: 'NAN' undeclared (first use in this function)
exp-combine.c:149: error: (Each undeclared identifier is reported only once
exp-combine.c:149: error: for each function it appears in.)
The error happens only on certain machines with some versions of gcc, and I it may happen in the most unexpected times...
So, I thought I'd share the solution for this problem with you since I had it in several more projects which use the NAN constant. Basically, NAN is a constant for a floating point value, which represents value that is Not A Number (not to be confused with the value which represents infinity). This value is usually (see note at the end) returned when dividing zero by zero, and therefore it can be added to gcc's definitions by adding the following argument to the command line:
-DNAN="(0.0/0.0)"
This is equivalent to adding the following line in C
#define NAN (0.0/0.0)
Now, there is only a little problem - what if we are not running GCC ourselves? What if a makefile or some other utility does this? Well, with most configure scripts (These scripts prepare the build environment and generate the makefiles) you can simply set the CFLAGS environment variable (before running the configure script) to fix this - in bash syntax this would be:
export CFLAGS="-DNAN=\"(0.0/0.0)\""
This solved my problems :)
Reference - http://old.nabble.com/Where-is-NAN-Defined--td15398150.html, http://linuxreviews.org/howtos/compiling/
As the original email list say, NAN is defined on some platforms and it's undefined on others, and our definition may not always work. From my experience, in the few cases were NAN wasn't defined, the fix presented here was enough.

Edit: I’d recommend checking the first comment below, from Martin Nordholts – he seems to offer another legitimate (and possibly more elegant) solution by telling GCC to use the gnu99 C standard.