From e824e7a0fada320600c3150437e532f8e6369f4b Mon Sep 17 00:00:00 2001 From: Lars Rademacher Date: Mon, 2 Dec 2013 17:18:32 +0100 Subject: [PATCH] cpn: Parsing of unsigned int fixed As atoi caps the value of a unsigned int bigger than (2^31 - 1) other than just letting it overflow to the corresponding negative value on 32Bit-integer machines, it must not be used for parsing to unsigned int. TODO: Also apply this fix to all other unsigned values (in database) which get parsed by atoi. Change-Id: I96e29b14d36479ab6e567c527a40feb0b5fb14e5 --- src/core/comm/DatabaseCampaignMessage.proto.in | 6 +++--- src/core/cpn/DatabaseCampaign.cc | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/comm/DatabaseCampaignMessage.proto.in b/src/core/comm/DatabaseCampaignMessage.proto.in index 442371f1..2dfae79a 100644 --- a/src/core/comm/DatabaseCampaignMessage.proto.in +++ b/src/core/comm/DatabaseCampaignMessage.proto.in @@ -15,11 +15,11 @@ message DatabaseCampaignMessage { // ToDo: injection_instr can be deleted if all experiments switched to // using generic InjectionPointMessage required int32 injection_instr = 4 [(sql_ignore) = true]; - optional int32 injection_instr_absolute = 5 [(sql_ignore) = true]; - required int32 data_address = 6 [(sql_ignore) = true]; + optional uint32 injection_instr_absolute = 5 [(sql_ignore) = true]; + required uint32 data_address = 6 [(sql_ignore) = true]; required int32 data_width = 7 [(sql_ignore) = true]; required string variant = 8 [(sql_ignore) = true]; required string benchmark = 9 [(sql_ignore) = true]; required InjectionPointMessage injection_point = 10 [(sql_ignore) = true]; -} \ No newline at end of file +} diff --git a/src/core/cpn/DatabaseCampaign.cc b/src/core/cpn/DatabaseCampaign.cc index 3b25b344..120283ed 100644 --- a/src/core/cpn/DatabaseCampaign.cc +++ b/src/core/cpn/DatabaseCampaign.cc @@ -144,7 +144,7 @@ bool DatabaseCampaign::run_variant(Database::Variant variant) { while ((row = mysql_fetch_row(pilots)) != 0) { unsigned pilot_id = atoi(row[0]); unsigned injection_instr = atoi(row[3]); - unsigned data_address = atoi(row[5]); + unsigned data_address = strtoul(row[5], NULL, 10); unsigned data_width = atoi(row[6]); @@ -161,7 +161,7 @@ bool DatabaseCampaign::run_variant(Database::Variant variant) { ip.addToCampaignMessage(pilot); if (row[4]) { - unsigned injection_instr_absolute = atoi(row[4]); + unsigned injection_instr_absolute = strtoul(row[4], NULL, 10); pilot.set_injection_instr_absolute(injection_instr_absolute); } pilot.set_data_address(data_address);