Uncertain mistake "Segmentation fault (core dumped)"

72 views
Skip to first unread message

Melody Liu

unread,
May 23, 2016, 6:08:20 AM5/23/16
to DataStax C++ Driver for Apache Cassandra User Mailing List
Hello,
I have come across a uncertain mistake "Segmentation fault" with no other debug information.

I'm going to execute batch operation based on the example code 'batch.c'. When I tried to compile the example code, there is no problem, however when I tried to execute it, there will be the mistake "Segmentation fault". I really don't know why......

The source code is /cpp-driver/examples/batch/batch.c

Here is my makefile:

CC = gcc

DEBUG = -g
CFLAGS = -Wall $(DEBUG) -I/home/mliu/Downloads/cpp-driver/include
LDFLAGS = -Wall $(DEBUG)

LIBS = -L/home/mliu/Downloads/cpp-driver/build -lcassandra

OBJS = batch.o

PROG = batch

%o: %c
$(CC) -c $(CFLAGS) $<

$(PROG): $(OBJS)
$(CC) $(LDFLAGS) $(OBJS) -o $(PROG) $(LIBS)

all: $(PROG)

.PHONY : clean
clean :
-rm -f $(OBJS) $(PROG)

Meng

Michael Penick

unread,
May 23, 2016, 7:41:22 PM5/23/16
to cpp-dri...@lists.datastax.com
I'm unable to reproduce on 'master' or the 2.3.0 release. Are you able to debug (using gdb or lldb) and provide a stacetrace?

Mike


--
You received this message because you are subscribed to the Google Groups "DataStax C++ Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cpp-driver-us...@lists.datastax.com.

Melody Liu

unread,
May 24, 2016, 3:39:09 AM5/24/16
to DataStax C++ Driver for Apache Cassandra User Mailing List
Hi Mike,

I have set some break point in the example code batch.c, this is the debug result:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6a544f0 in std::string::data() const ()
from /usr/lib/x86_64-linux-gnu/libstdc++.so.6

This mistake occurs to this part of code in main():

if (prepare_insert_into_batch(session, &prepared) == CASS_OK) {
insert_into_batch_with_prepared(session, prepared, pairs);
}

The prepare_insert into batch():

CassError prepare_insert_into_batch(CassSession* session, const CassPrepared** prepared) {
CassError rc = CASS_OK;
CassFuture* future = NULL;
const char* query = "INSERT INTO examples.pairs (key, value) VALUES (?, ?)";

future = cass_session_prepare(session, query);
cass_future_wait(future);

rc = cass_future_error_code(future);
if (rc != CASS_OK) {
print_error(future);
} else {
*prepared = cass_future_get_prepared(future);
}

cass_future_free(future);

return rc;
}

The insert_into_batch_with_prepared():

CassError insert_into_batch_with_prepared(CassSession* session, const CassPrepared* prepared, const Pair* pairs) {
CassError rc = CASS_OK;
CassFuture* future = NULL;
CassBatch* batch = cass_batch_new(CASS_BATCH_TYPE_LOGGED);

const Pair* pair;
for (pair = pairs; pair->key != NULL; pair++) {
CassStatement* statement = cass_prepared_bind(prepared);
cass_statement_bind_string(statement, 0, pair->key);
cass_statement_bind_string(statement, 1, pair->value);
cass_batch_add_statement(batch, statement);
cass_statement_free(statement);
}

{
CassStatement* statement = cass_statement_new("INSERT INTO examples.pairs (key, value) VALUES ('c', '3')", 0);
cass_batch_add_statement(batch, statement);
cass_statement_free(statement);
}

{
CassStatement* statement = cass_statement_new("INSERT INTO examples.pairs (key, value) VALUES (?, ?)", 2);
cass_statement_bind_string(statement, 0, "d");
cass_statement_bind_string(statement, 1, "4");
cass_batch_add_statement(batch, statement);
cass_statement_free(statement);
}

future = cass_session_execute_batch(session, batch);
cass_future_wait(future);

rc = cass_future_error_code(future);
if (rc != CASS_OK) {
print_error(future);
}

I think that there is something wrong with the prepare process, because when I tried to use only batch operation, it works well.

Meng


在 2016年5月24日星期二 UTC+2上午1:41:22,Michael Penick写道:
Reply all
Reply to author
Forward
0 new messages