util/status.cc

filter: Statementstmt 60.7% 31 / 51 Branchbran 66.6% 12 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 62.3% 43 / 69 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« db/table_cache.cc ↑ Summary util/hash.cc »
1 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. See the AUTHORS file for names of contributors.
4  
5 #include <stdio.h>
6 #include "port/port.h"
7 #include "leveldb/status.h"
8  
9 namespace leveldb {
10  
11 15 const char* Status::CopyState(const char* state) {
12 uint32_t size;
13 15 memcpy(&size, state, sizeof(size));
14 15 ▶ char* result = new char[size + 5];
Branch: 1 branch
BranchTrueFalseTotal
char* result = new char[size + 5]; 15 0 15
15 15 memcpy(result, state, size + 5);
16 15 return result;
17 }
18  
19 14 Status::Status(Code code, const Slice& msg, const Slice& msg2) {
20 14 ▶ assert(code != kOk);
Branch: 1 branch
BranchTrueFalseTotal
assert(code != kOk); 0 14 14
21 14 const uint32_t len1 = msg.size();
22 14 const uint32_t len2 = msg2.size();
23 14 ▶ const uint32_t size = len1 + (len2 ? (2 + len2) : 0);
Branch: 1 branch
BranchTrueFalseTotal
const uint32_t size = len1 + (len2 ? (2 + len2) : 0); 9 5 14
24 14 ▶ char* result = new char[size + 5];
Branch: 1 branch
BranchTrueFalseTotal
char* result = new char[size + 5]; 14 0 14
25 14 memcpy(result, &size, sizeof(size));
26 14 result[4] = static_cast<char>(code);
27 14 memcpy(result + 5, msg.data(), len1);
28 14 ▶ if (len2) {
Branch: 1 branch
BranchTrueFalseTotal
if (len2) { 9 5 14
29 9 result[5 + len1] = ':';
30 9 result[6 + len1] = ' ';
31 9 memcpy(result + 7 + len1, msg2.data(), len2);
32 }
33 14 state_ = result;
34 14 }
35  
36 2 std::string Status::ToString() const {
37 2 ▶ if (state_ == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (state_ == NULL) { 1 1 2
38 2 ▶ return "OK";
Branch: 1 branch
BranchTrueFalseTotal
return "OK"; 1 0 1
39 } else {
40 char tmp[30];
41 const char* type;
42 1 switch (code()) {
43 0 case kOk:
44 0 type = "OK";
45 0 break;
46 0 case kNotFound:
47 0 type = "NotFound: ";
48 0 break;
49 0 case kCorruption:
50 0 type = "Corruption: ";
51 0 break;
52 0 case kNotSupported:
53 0 type = "Not implemented: ";
54 0 break;
55 0 case kInvalidArgument:
56 0 type = "Invalid argument: ";
57 0 break;
58 1 case kIOError:
59 1 type = "IO error: ";
60 1 break;
61 0 default:
62 0 snprintf(tmp, sizeof(tmp), "Unknown code(%d): ",
63 0 static_cast<int>(code()));
64 0 type = tmp;
65 0 break;
66 }
67 2 ▶ std::string result(type);
Branch: 1 branch
BranchTrueFalseTotal
std::string result(type); 1 0 1
68 uint32_t length;
69 1 memcpy(&length, state_, sizeof(length));
70 1 ▶ result.append(state_ + 5, length);
Branch: 1 branch
BranchTrueFalseTotal
result.append(state_ + 5, length); 1 0 1
71 1 return result;
72 }
73 }
74  
75 }
« db/table_cache.cc ↑ Summary util/hash.cc »