lxbzmy / java-simple-serial-connector

Automatically exported from code.google.com/p/java-simple-serial-connector
0 stars 0 forks source link

Incorrect on stack memory allocation #43

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I am not going to provide u with the steps or something like that. 
Just take a look at the following code:

    //since 2.1.0 -> string concat fix
    char portFullName[strlen(prefix) + strlen(port) + 1];

How is that going to work? In C++ you can not allocate the array by this way 
because strlen(prefix) + strlen(port) gives u the correct value on the runtime 
only! At the compiling time the size of the array is not exactly known so that 
memory can not be correctly allocated on the stack.

So u probably need to call alloca here unless your code will corrupt my stack.

Thanks. 

Alexey K.

Original issue reported on code.google.com by akakiy.k...@gmail.com on 23 Jul 2013 at 10:31