Skip to content

Commit

Permalink
dcm loader segfault hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Tooley committed Feb 22, 2019
1 parent a0f1b15 commit 47d8bdb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
21 changes: 17 additions & 4 deletions src/dcmloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,31 @@ void DCMLoader::copy_scaled_chunk(
{
integer flat_idx = (col_idx + offset[1]) * size[0] + offset[0];
integer frame_idx = slice_idx - offset[2];
floating* array_slice_ptr = data[slice_idx][col_idx];
if(!array_slice_ptr)
{
throw InternalError("Out of bounds array access", __FILE__, __LINE__);
}
switch (bitdepth)
{
case 8:
{
uint8_t *rawdata = (uint8_t *)img.getOutputData(8, slice_idx, 0);
norm_convert(data[frame_idx][col_idx], rawdata + flat_idx, size[0], dmin, dmax);
uint8_t *rawdata = (uint8_t *)img.getOutputData(8, frame_idx, 0);
if (!rawdata)
{
throw InternalError("MPI dicom read failed", __FILE__, __LINE__);
}
norm_convert(array_slice_ptr, rawdata + flat_idx, size[0], dmin, dmax);
break;
}
case 16:
{
uint16_t *rawdata = (uint16_t *)img.getOutputData(16, slice_idx, 0);
norm_convert(data[frame_idx][col_idx], rawdata + flat_idx, size[0], dmin, dmax);
uint16_t *rawdata = (uint16_t *)img.getOutputData(16, frame_idx, 0);
if (!rawdata)
{
throw InternalError("MPI dicom read failed", __FILE__, __LINE__);
}
norm_convert(array_slice_ptr, rawdata + flat_idx, size[0], dmin, dmax);
break;
}
default:
Expand Down
31 changes: 25 additions & 6 deletions src/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@

#include <sstream>

#include "types.hpp"

void abort_with_unhandled_error();
void sigterm_handler(int signal);

class InvalidLoaderError : public std::runtime_error {
class InvalidLoaderError: public std::runtime_error {
public:
InvalidLoaderError(const std::string& filepath)
: std::runtime_error(build_errstring(filepath)) {}
InvalidLoaderError(const std::string& filepath) : std::runtime_error(build_errstring(filepath))
{
}

protected:
static std::string build_errstring(const std::string& path)
Expand All @@ -35,10 +38,9 @@ class InvalidLoaderError : public std::runtime_error {
}
};

class FileNotFoundError : public std::runtime_error {
class FileNotFoundError: public std::runtime_error {
public:
FileNotFoundError(const std::string& filepath)
: std::runtime_error(build_errstring(filepath)) {}
FileNotFoundError(const std::string& filepath) : std::runtime_error(build_errstring(filepath)) {}

protected:
static std::string build_errstring(const std::string& path)
Expand All @@ -49,4 +51,21 @@ class FileNotFoundError : public std::runtime_error {
}
};

class InternalError: public std::runtime_error {
public:
InternalError(const std::string& what, std::string file = "unknown", integer line = 0)
: std::runtime_error(build_errstring(what, file, line))
{
}

protected:
static std::string build_errstring(
const std::string& what, std::string file, integer line)
{
std::ostringstream errss;
errss << "Internal error at " << file << ":" << line << " \"" << what << "\"";
return errss.str();
}
};

#endif // EXCEPTIONS_HPP

0 comments on commit 47d8bdb

Please sign in to comment.