• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / mender-flash / 1498380744

16 Oct 2024 11:47AM UTC coverage: 67.203% (-24.7%) from 91.892%
1498380744

push

gitlab-ci

kacf
build: Add `-Wconversion` to catch more 32 vs 64 bit errors.

Ticket: MEN-7613

Signed-off-by: Kristian Amlie <kristian.amlie@northern.tech>
(cherry picked from commit 606ed7449)

0 of 1 new or added line in 1 file covered. (0.0%)

9 existing lines in 3 files now uncovered.

209 of 311 relevant lines covered (67.2%)

12.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/common/io.hpp
1
// Copyright 2023 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
#ifndef MENDER_COMMON_IO_HPP
16
#define MENDER_COMMON_IO_HPP
17

18
#include <common/error.hpp>
19
#include <common/expected.hpp>
20

21
#include <memory>
22
#include <system_error>
23
#include <vector>
24
#include <istream>
25
#include <sstream>
26
#include <string>
27

28
namespace mender {
29
namespace common {
30
namespace io {
31

32
using namespace std;
33
namespace expected = mender::common::expected;
34

35
using mender::common::error::Error;
36
using mender::common::error::NoError;
37

38
using ExpectedSize = expected::ExpectedSize;
39
using ExpectedSize64 = expected::ExpectedSize64;
40

41
class Reader {
42
public:
UNCOV
43
        virtual ~Reader() {};
×
44

45
        virtual ExpectedSize Read(vector<uint8_t>::iterator start, vector<uint8_t>::iterator end) = 0;
46
};
47
using ReaderPtr = shared_ptr<Reader>;
48
using ExpectedReaderPtr = expected::expected<ReaderPtr, Error>;
49

50
class Writer {
51
public:
UNCOV
52
        virtual ~Writer() {};
×
53

54
        virtual ExpectedSize Write(
55
                vector<uint8_t>::const_iterator start, vector<uint8_t>::const_iterator end) = 0;
56
};
57
using WriterPtr = shared_ptr<Writer>;
58
using ExpectedWriterPtr = expected::expected<WriterPtr, Error>;
59

60
class ReadWriter : virtual public Reader, virtual public Writer {};
61
using ReadWriterPtr = shared_ptr<ReadWriter>;
62
using ExpectedReadWriterPtr = expected::expected<ReadWriterPtr, Error>;
63

64
/**
65
 * Stream the data from `src` to `dst` until encountering EOF or an error.
66
 */
67
Error Copy(Writer &dst, Reader &src);
68

69
/**
70
 * Stream the data from `src` to `dst` until encountering EOF or an error, using `buffer` as an
71
 * intermediate. The block size will be the size of `buffer`.
72
 */
73
Error Copy(Writer &dst, Reader &src, vector<uint8_t> &buffer);
74

75
class StreamReader : virtual public Reader {
76
private:
77
        std::istream &is_;
78

79
public:
80
        StreamReader(std::istream &stream) :
81
                is_ {stream} {
82
        }
83
        StreamReader(std::istream &&stream) :
84
                is_ {stream} {
85
        }
86
        ExpectedSize Read(vector<uint8_t>::iterator start, vector<uint8_t>::iterator end) override {
87
                is_.read(reinterpret_cast<char *>(&*start), end - start);
88
                if (is_.bad()) {
89
                        int int_error = errno;
90
                        return expected::unexpected(Error(
91
                                std::error_code(int_error, std::generic_category()).default_error_condition(), ""));
92
                }
93
                return is_.gcount();
94
        }
95
};
96

97
/* Discards all data written to it */
98
class Discard : virtual public Writer {
99
        ExpectedSize Write(
100
                vector<uint8_t>::const_iterator start, vector<uint8_t>::const_iterator end) override {
101
                return end - start;
102
        }
103
};
104

105
class StringReader : virtual public Reader {
106
private:
107
        std::stringstream s_;
108
        StreamReader reader_;
109

110
public:
111
        StringReader(string &str) :
112
                s_ {str},
113
                reader_ {s_} {
114
        }
115
        StringReader(string &&str) :
116
                s_ {str},
117
                reader_ {s_} {
118
        }
119

120
        ExpectedSize Read(vector<uint8_t>::iterator start, vector<uint8_t>::iterator end) override {
121
                return reader_.Read(start, end);
122
        }
123
};
124

125
} // namespace io
126
} // namespace common
127
} // namespace mender
128

129
#endif // MENDER_COMMON_IO_HPP
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc