Error in using pcap loop with mysql con as My argument - mysql

I want to add the mysql connection with the pcap loop which I am using in the code
MYSQL *con;
u_char *my_arguments = con;
pcap_loop(handle, total_packet_count, my_packet_handler, my_arguments);
but it is giving error
warning: initialization from incompatible pointer type
[-Wincompatible-pointer-types]
u_char *my_arguments = con;^~~
SO what should I do help is needed please
When I am directly putting value of con in pcap loop like pcap_loop(handle, total_packet_count, my_packet_handler, con); it is showing new error
Error is
passing argument 4 of ‘pcap_loop’ from incompatible pointer type
[-Wincompatible-pointer-types]
pcap_loop(handle, total_packet_count, my_packet_handler, con);
note: expected ‘u_char * {aka unsigned char *}’ but argument is of type ‘MYSQL * {aka struct st_mysql *}’
PCAP_API int pcap_loop(pcap_t *, int, pcap_handler, u_char *);
but I want it to be pushed in pcap loop

The "user" argument to pcap_loop(), pcap_dispatch(), and the callback probably should have been defined to be a void *, as it's a pointer to some arbitrary data that the callback understands, but it was defined to be a u_char * instead.
So you should cast the MYSQL * to u_char *:
pcap_loop(handle, total_packet_count, my_packet_handler, (u_char *)con);

Related

"Storing unsafe C derivative of temporary Python reference" when trying to access struct pointer

I want to use a library that gives me a dynamic array. The dynamic array struct has a property void* _heap_ptr which gives the start of the array.
After having built the list, I want to access this pointer in cython (to make a copy of the array). But I cannot seem to get the pointer element from the struct.
Here is my pyx:
cimport src.clist as l
def main():
cdef l.ptr_list basic_list
cdef int i = 42
basic_list = l.create_list_size(sizeof(i), 100)
l.list_add_ptr(basic_list, &i)
cdef int* arr;
arr = basic_list._heap_ptr
for i in range(1):
print(arr[i])
This is the error message:
Error compiling Cython file:
------------------------------------------------------------
...
l.list_add_ptr(basic_list, &i)
cdef int* arr;
arr = basic_list._heap_ptr
^
------------------------------------------------------------
src/test.pyx:14:20: Cannot convert Python object to 'int *'
Error compiling Cython file:
------------------------------------------------------------
...
l.list_add_ptr(basic_list, &i)
cdef int* arr;
arr = basic_list._heap_ptr
^
------------------------------------------------------------
src/test.pyx:14:20: Storing unsafe C derivative of temporary Python reference
And my pxd:
cdef extern from "src/list.h":
ctypedef struct _list:
void* _heap_ptr
ctypedef struct ptr_list:
pass
ptr_list create_list_size(size_t size, int length)
list_destroy(ptr_list this_list)
void* list_at_ptr(ptr_list this_list, int index)
list_add_ptr(ptr_list this_list, void* value)
How can I fix my code? Why is this happening? From my investigations that error message pops up if you have forgotten to declare something as C (ie. use malloc not libc.stdlib.malloc, but I cannot see that anything similar is happening here.)
There are two issues in your code.
First: struct ptr_list has no members and thus no member _heap_ptr. It probably should have been
ctypedef struct ptr_list:
void* _heap_ptr
Cython's error message is not really helpful here, but as you said it pops up usually when a C-declaration is forgotten.
Second: you need to cast from void * to int * explicitly:
arr = <int*>basic_list._heap_ptr

Clang-tidy false positive with boost::variant

When running clang-tidy on this minimal example posted below I get the (imho) false positive error from clang-tidy (full error trace at the end)
Value assigned to field 'id' in implicit constructor is garbage or undefined [clang-analyzer-core.uninitialized.Assign]
The code does nothing but assign a boost::variant to one of the two values. The error is gone if I replace the copy constructor by Size(const Size& sz) = default;. However, I cannot do this, since the Size is a cv::Size in the real code.
Even though it might not be as elegant as possible, I don't see any error with this. Can somebody point me into the direction if I am mistaken, clang-tidy or boost.
#include <boost/variant.hpp>
class Size
{
public:
Size() = default;
Size(const Size &sz) : width(sz.width) {}
int width{0};
};
struct B {
Size size;
};
struct A {
Size size;
uint32_t id{0};
};
int main() {
using T = boost::variant<A, B>;
T config = B();
}
I am running:
clang-tools-extra commit 50fe75789f08b96284d2c14cb6583b3783c74460
llvm commit afb8c1fed21eb4848d86f2d28e9cb3afcfbb2656
boost 1.67
Full error dump:
test_variant.cc:15:8: warning: Value assigned to field 'id' in implicit constructor is garbage or undefined [clang-analyzer-core.uninitialized.Assign]
struct A {
^
test_variant.cc:22:5: note: Calling move constructor for 'variant'
T config = B();
^
libraries/boost/include/boost/variant/variant.hpp:1880:9: note: Calling 'variant::internal_apply_visitor'
operand.internal_apply_visitor(visitor);
^
libraries/boost/include/boost/variant/variant.hpp:2466:16: note: Calling 'variant::internal_apply_visitor_impl'
return internal_apply_visitor_impl(
^
libraries/boost/include/boost/variant/variant.hpp:2452:16: note: Calling 'visitation_impl'
return detail::variant::visitation_impl(
^
libraries/boost/include/boost/variant/detail/visitation_impl.hpp:225:5: note: Control jumps to 'case 0:' at line 238
switch (logical_which)
^
libraries/boost/include/boost/variant/detail/visitation_impl.hpp:240:11: note: Calling 'visitation_impl_invoke'
, BOOST_VARIANT_AUX_APPLY_VISITOR_STEP_CASE
^
libraries/boost/include/boost/preprocessor/repetition/repeat.hpp:29:26: note: expanded from macro 'BOOST_PP_REPEAT'
# define BOOST_PP_REPEAT BOOST_PP_CAT(BOOST_PP_REPEAT_, BOOST_PP_AUTO_REC(BOOST_PP_REPEAT_P, 4))
^
libraries/boost/include/boost/preprocessor/cat.hpp:22:32: note: expanded from macro 'BOOST_PP_CAT'
# define BOOST_PP_CAT(a, b) BOOST_PP_CAT_I(a, b)
^
libraries/boost/include/boost/preprocessor/cat.hpp:29:34: note: expanded from macro 'BOOST_PP_CAT_I'
# define BOOST_PP_CAT_I(a, b) a ## b
^
note: (skipping 21 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
libraries/boost/include/boost/preprocessor/repetition/repeat.hpp:53:56: note: expanded from macro 'BOOST_PP_REPEAT_1_2'
# define BOOST_PP_REPEAT_1_2(m, d) BOOST_PP_REPEAT_1_1(m, d) m(2, 1, d)
^
libraries/boost/include/boost/preprocessor/repetition/repeat.hpp:52:36: note: expanded from macro 'BOOST_PP_REPEAT_1_1'
# define BOOST_PP_REPEAT_1_1(m, d) m(2, 0, d)
^
libraries/boost/include/boost/variant/detail/visitation_impl.hpp:231:16: note: expanded from macro 'BOOST_VARIANT_AUX_APPLY_VISITOR_STEP_CASE'
return (visitation_impl_invoke)( \
^
libraries/boost/include/boost/variant/detail/visitation_impl.hpp:154:12: note: Calling 'visitation_impl_invoke_impl'
return (visitation_impl_invoke_impl)(
^
libraries/boost/include/boost/variant/detail/visitation_impl.hpp:112:12: note: Calling 'move_into::internal_visit'
return visitor.internal_visit(
^
libraries/boost/include/boost/variant/variant.hpp:507:23: note: Calling implicit move constructor for 'A'
new(storage_) T(::boost::detail::variant::move(operand));
^
test_variant.cc:15:8: note: Value assigned to field 'id' in implicit constructor is garbage or undefined
struct A {

number(X) as function parameter or return value generates PLS 00103 error

I have the following function definition:
create or replace FUNCTION checkXML
(idx in number(19))
return number(19)
is
...
But when I compile it, am getting the following errors,
Error(2,16): PLS-00103: Encountered the symbol "(" when expecting one of the
following: := . ) , # % default character The symbol ":=" was substituted for
"(" to continue.
Error(3,15): PLS-00103: Encountered the symbol "(" when expecting one of the
following: . # % ; is authid as cluster order using external character
deterministic parallel_enable pipelined aggregate result_cache
Change the function declaraction to be
create or replace FUNCTION checkXML
(idx in number)
return number
PL/SQL doesn't accept length or precision specifiers on parameters or return types.
Share and enjoy.

Error : argument of type "int" is incompatible with parameter of type "const void *"

in this part of my code when compile program. this error show: "argument of type "int" is incompatible with parameter of type "const void *". i declare variable as follow:
int *dev_matrix, *dev_array, *dev_array_length;
int array_length=1;
cudaMalloc((void**)&dev_array_length, 1*sizeof(int));
cudaMemcpy(dev_array_length, array_length, 1*sizeof(int), cudaMemcpyHostToDevice);
The second argument to cudaMemcpy() is wrong. It is meant to be a pointer (const void*) and you're supplying an int.
Did you mean to write:
cudaMemcpy(dev_array_length, &array_length, 1*sizeof(int), cudaMemcpyHostToDevice);
^

Get data with a c program from an HTML form

I have created the following C program to get data from an HTML form. But when I try to compile and run it, I get:
segmentation fault 11 (core dumped)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main()
{
char *N1,*N2,*N3,*N4,*N5;
int cgi_length;
char *cgi_data;
printf("Content-type:text/html\n\n");
cgi_length=atoi(getenv("CONTENT_LENGTH"));
cgi_data=malloc(cgi_length+1);
fread(cgi_data,1,cgi_length,stdin);
printf("<HTML>");
printf("<HEAD><TITLE>DATA</TITLE></HEAD><BODY>\n");
printf("<H3>DATA</H3>\n");
if(cgi_data == NULL)
{
printf("<P>Error! Error in passing data from form to script.");
}
else {
printf("%s",cgi_data);
sscanf(cgi_data,"N1=%s&N2=%s&N3=%S&N4=%SN5=%s",&N1,&N2,&N3,&N4,&N5);
printf("<P>N1 is %s and N2 is %s and N3 is %S and N4 is %S and N5 is %s.",N1,N2,N3,N4,N5);
}
}
Also if I use the ls command to see the data in the cgi-bin directory I see that a file named myprogram.cgi.core is created.
Does anyone know what is wrong?
I had the same problem before. I used fgets in a while loop. fread didn't work for me. Try this:
cgi_length=atoi(getenv("CONTENT_LENGTH"));
cgi_data=malloc(cgi_length+1);
while(fgets(cgi_data,cgi_length,stdin)!=NULL){
//insert some processing here
}
You have to check that the return value of your getenv function call is not a null pointer. Passing a null pointer to atoi is undefined behavior. I suggest also to check the return value of all your function calls and to use strtol function instead of atoi because atoi cannot detect errors.
Load the coredump in GDB. Try something like:
gdb myprogram.cgi myprogram.cgi.core
maybe replace myprogram.cgi with the proper name of the CGI.
When you are in GDB you could get a back trace to see where the application crashed by typing bt in the console.
Here you can find a quick tutorial on howto GDB: http://cs.baylor.edu/~donahoo/tools/gdb/tutorial.html
Few notes...:
Check what getenv returns, maybe it returns NULL instead of the value of the environment variable.
sscanf copies the values of the strings to the buffers where N1 N2 N3 N4 N5 are pointing to, it would be wise to allocate some memory for those pointers first...
You don't have to get the reference of the points N1 N2 N3 N4 N5
As Daniel Fischer noted: fread doesn't 0 terminate the string.
If you compile with -Wall (all warnings), it will give you an idea what's wrong
cgi.c: In function ‘main’:
cgi.c:23:9: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘char **’ [-Wformat]
cgi.c:23:9: warning: format ‘%s’ expects argument of type ‘char *’, but argument 4 has type ‘char **’ [-Wformat]
cgi.c:23:9: warning: format ‘%S’ expects argument of type ‘wchar_t *’, but argument 5 has type ‘char **’ [-Wformat]
cgi.c:23:9: warning: format ‘%S’ expects argument of type ‘wchar_t *’, but argument 6 has type ‘char **’ [-Wformat]
cgi.c:23:9: warning: format ‘%s’ expects argument of type ‘char *’, but argument 7 has type ‘char **’ [-Wformat]
cgi.c:24:9: warning: format ‘%S’ expects argument of type ‘wchar_t *’, but argument 4 has type ‘char *’ [-Wformat]
cgi.c:24:9: warning: format ‘%S’ expects argument of type ‘wchar_t *’, but argument 5 has type ‘char *’ [-Wformat]
cgi.c:26:1: warning: control reaches end of non-void function [-Wreturn-type]
There are several fundamental C programming errors. Use e.g. lint to find out some of them. For example, you’re declaring N1 as a character pointer but do not initialize it, and you pass its address as argument. You need to allocate a character array somehow and pass a pointer to it as an argument to sscanf.
I am pretty sure that you are getting zero in this line
cgi_length=atoi(getenv("CONTENT_LENGTH"));
Check if there is this environment variable actually defined. And always check for sizes before allocating memory and before putting some data into it.