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

paulmthompson / WhiskerToolbox / 17365621401

01 Sep 2025 02:02AM UTC coverage: 71.945%. First build
17365621401

push

github

paulmthompson
fix use after free in destructor of media_window

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

31745 of 44124 relevant lines covered (71.94%)

1400.39 hits per line

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

16.51
/src/DataManager/IO/HDF5/HDF5Loader.cpp
1
#include "HDF5Loader.hpp"
2
#include "../LoaderRegistry.hpp"
3
#include "CoreGeometry/lines.hpp"
4
#include "CoreGeometry/masks.hpp"
5
#include "CoreGeometry/points.hpp"
6
#include "IO/interface/DataFactory.hpp"
7
#include "hdf5_loaders.hpp"
8

9
#include <iostream>
10

11
std::string HDF5Loader::getFormatId() const {
×
12
    return "hdf5";
×
13
}
14

15
bool HDF5Loader::supportsDataType(IODataType data_type) const {
×
16
    using enum IODataType;
17
    switch (data_type) {
×
18
        case Mask:
×
19
        case Line:
20
            return true;
×
21
        default:
×
22
            return false;
×
23
    }
24
}
25

26
LoadResult HDF5Loader::loadData(
1✔
27
    std::string const& file_path,
28
    IODataType data_type,
29
    nlohmann::json const& config,
30
    DataFactory* factory
31
) const {
32
    if (!factory) {
1✔
33
        return LoadResult("Factory is null");
×
34
    }
35
    
36
    try {
37
        using enum IODataType;
38
        if (data_type == Mask) {
1✔
39
            return loadMaskData(file_path, config, factory);
×
40
        }
41
        if (data_type == Line) {
1✔
42
            return loadLineData(file_path, config, factory);
1✔
43
        }
44
        return LoadResult("Unsupported data type for HDF5 loader");
×
45
    } catch (std::exception const& e) {
×
46
        return LoadResult("HDF5 loading error: " + std::string(e.what()));
×
47
    }
×
48
}
49

50
LoadResult HDF5Loader::loadMaskData(
×
51
    std::string const& file_path,
52
    nlohmann::json const& config,
53
    DataFactory* factory
54
) const {
55
    try {
56
        // Extract configuration with defaults
57
        std::string frame_key = "frames";
×
58
        std::string x_key = "widths";
×
59
        std::string y_key = "heights";
×
60
        
61
        if (config.contains("frame_key")) {
×
62
            frame_key = config["frame_key"].get<std::string>();
×
63
        }
64
        if (config.contains("x_key")) {
×
65
            x_key = config["x_key"].get<std::string>();
×
66
        }
67
        if (config.contains("y_key")) {
×
68
            y_key = config["y_key"].get<std::string>();
×
69
        }
70
        
71
        // Load data using HDF5 utilities
72
        auto frames = Loader::read_array_hdf5({file_path, frame_key});
×
73
        auto x_coords = Loader::read_ragged_hdf5({file_path, x_key});
×
74
        auto y_coords = Loader::read_ragged_hdf5({file_path, y_key});
×
75
        
76
        if (frames.empty() && x_coords.empty() && y_coords.empty()) {
×
77
            return LoadResult("No data found in HDF5 file: " + file_path);
×
78
        }
79
        
80
        // Convert to raw data format
81
        MaskDataRaw raw_data;
×
82
        
83
        for (std::size_t i = 0; i < frames.size(); i++) {
×
84
            int32_t frame = frames[i];
×
85
            std::vector<Mask2D> frame_masks;
×
86
            
87
            if (i < x_coords.size() && i < y_coords.size()) {
×
88
                Mask2D mask_points;
×
89
                
90
                auto const& x_vec = x_coords[i];
×
91
                auto const& y_vec = y_coords[i];
×
92
                
93
                size_t min_size = std::min(x_vec.size(), y_vec.size());
×
94
                for (size_t j = 0; j < min_size; j++) {
×
95
                    mask_points.push_back(Point2D<uint32_t>(
×
96
                        static_cast<uint32_t>(x_vec[j]),
×
97
                        static_cast<uint32_t>(y_vec[j]))
×
98
                    );
99
                }
100
                
101
                if (!mask_points.empty()) {
×
102
                    frame_masks.push_back(std::move(mask_points));
×
103
                }
104
            }
×
105
            
106
            if (!frame_masks.empty()) {
×
107
                raw_data.time_masks[frame] = std::move(frame_masks);
×
108
            }
109
        }
×
110
        
111
        // Extract image size from config if available
NEW
112
        if (config.contains("width")) {
×
NEW
113
            raw_data.image_width = config["width"].get<uint32_t>();
×
114
        }
NEW
115
        if (config.contains("height")) {
×
NEW
116
            raw_data.image_height = config["height"].get<uint32_t>();
×
117
        }
118
        
119
        // Create MaskData using factory
120
        auto mask_data = factory->createMaskDataFromRaw(raw_data);
×
121
        
122
        std::cout << "HDF5 mask loading complete: " << frames.size() << " frames loaded" << std::endl;
×
123
        
124
        return LoadResult(std::move(mask_data));
×
125
        
126
    } catch (std::exception const& e) {
×
127
        return LoadResult("Error loading HDF5 mask data: " + std::string(e.what()));
×
128
    }
×
129
}
×
130

131
LoadResult HDF5Loader::loadLineData(
1✔
132
    std::string const& file_path,
133
    nlohmann::json const& config,
134
    DataFactory* factory
135
) const {
136
    try {
137
        // Extract configuration with defaults
138
        std::string frame_key = "frames";
3✔
139
        std::string x_key = "y";  // Note: x and y are swapped in the original implementation
3✔
140
        std::string y_key = "x";
3✔
141
        
142
        if (config.contains("frame_key")) {
1✔
143
            frame_key = config["frame_key"].get<std::string>();
1✔
144
        }
145
        if (config.contains("x_key")) {
1✔
146
            x_key = config["x_key"].get<std::string>();
1✔
147
        }
148
        if (config.contains("y_key")) {
1✔
149
            y_key = config["y_key"].get<std::string>();
1✔
150
        }
151
        
152
        // Load data using HDF5 utilities
153
        auto frames = Loader::read_array_hdf5({file_path, frame_key});
3✔
154
        auto x_coords = Loader::read_ragged_hdf5({file_path, x_key});
×
155
        auto y_coords = Loader::read_ragged_hdf5({file_path, y_key});
×
156
        
157
        if (frames.empty() && x_coords.empty() && y_coords.empty()) {
×
158
            return LoadResult("No data found in HDF5 file: " + file_path);
×
159
        }
160
        
161
        // Convert to raw data format
162
        LineDataRaw raw_data;
×
163
        
164
        for (std::size_t i = 0; i < frames.size(); i++) {
×
165
            int32_t frame = frames[i];
×
166
            std::vector<Line2D> frame_lines;
×
167
            
168
            if (i < x_coords.size() && i < y_coords.size()) {
×
169
                Line2D line;
×
170
                
171
                auto const& x_vec = x_coords[i];
×
172
                auto const& y_vec = y_coords[i];
×
173
                
174
                size_t min_size = std::min(x_vec.size(), y_vec.size());
×
175
                for (size_t j = 0; j < min_size; j++) {
×
176
                    line.push_back(Point2D<float>(x_vec[j], y_vec[j]));
×
177
                }
178

179
                if (!line.empty()) {
×
180
                    frame_lines.push_back(std::move(line));
×
181
                }
182
            }
×
183
            
184
            if (!frame_lines.empty()) {
×
185
                raw_data.time_lines[frame] = std::move(frame_lines);
×
186
            }
187
        }
×
188
        
189
        // Extract image size from config if available
190
        if (config.contains("image_width")) {
×
191
            raw_data.image_width = config["image_width"].get<uint32_t>();
×
192
        }
193
        if (config.contains("image_height")) {
×
194
            raw_data.image_height = config["image_height"].get<uint32_t>();
×
195
        }
196
        
197
        // Create LineData using factory
198
        auto line_data = factory->createLineDataFromRaw(raw_data);
×
199
        
200
        std::cout << "HDF5 line loading complete: " << frames.size() << " frames loaded" << std::endl;
×
201
        
202
        return LoadResult(std::move(line_data));
×
203
        
204
    } catch (std::exception const& e) {
4✔
205
        return LoadResult("Error loading HDF5 line data: " + std::string(e.what()));
×
206
    }
×
207
}
2✔
208

209
// Note: HDF5 registration is now handled by the LoaderRegistration system
210
// The HDF5FormatLoader wraps this class for the new registry system
211

212
// Keep this function for backward compatibility - some code may still call it
213
extern "C" void ensure_hdf5_loader_registration() {
×
214
    // This function does nothing but ensures the object file is linked
215
    // Registration is now handled automatically by LoaderRegistration
216
}
×
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

© 2026 Coveralls, Inc