fixed bug with debug build

master v1.2.1
Avril 4 years ago
parent 64af32ed33
commit 1c40c87c2c
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -48,7 +48,7 @@ $(PROJECT)-release: $(OBJ)
strip $@
$(PROJECT)-debug: CXXFLAGS = -O0 -g -Wall -pedantic --std=gnu++20 $(addprefix -I,$(INCLUDE)) -fno-exceptions -felide-constructors
$(PROJECT)-debug: CXXFLAGS = -DDEBUG -O0 -g -Wall -pedantic --std=gnu++20 $(addprefix -I,$(INCLUDE)) -fno-exceptions -felide-constructors
$(PROJECT)-debug: LDFLAGS = -lfmt
$(PROJECT)-debug: $(OBJ)
$(CXX) $^ $(CXXFLAGS) -o $@ $(LDFLAGS)

@ -20,14 +20,14 @@ namespace hv
inline T& operator[](std::size_t index)
{
#ifdef DEBUG
if (index>=len) throw "tried to index out of bounds of array";
if (index>=len) std::terminate(); // "tried to index out of bounds of array";
#endif
return ptr[index];
}
inline const T& operator[](std::size_t index) const
{
#ifdef DEBUG
if (index>=len) throw "tried to index out of bounds of array";
if (index>=len) std::terminate(); // "tried to index out of bounds of array";
#endif
return ptr[index];
}
@ -35,12 +35,12 @@ namespace hv
inline span<T> slice(std::size_t off, std::size_t len)
{
len = std::min(this->len, len);
if(len+off>=len || len < off) throw "tried to index out of bounds of array";
if(len+off>=len || len < off) std::terminate(); // "tried to index out of bounds of array";
return span<T>(ptr+off, len-off);
}
inline span<T> slice(std::size_t off)
{
if(len+off>=len || len < off) throw "tried to index out of bounds of array";
if(len+off>=len || len < off) std::terminate(); // "tried to index out of bounds of array";
return span<T>(ptr+off, len-off);
}

@ -59,6 +59,12 @@ inline void hex02(std::uint8_t byte, char buffer[2])
buffer[1] =hex_map[byte][1];
}
template<std::size_t N>
inline __attribute((always_inline)) void print_exact(const char* ar)
{
fwrite(ar, 1, N, stdout);
}
template<std::size_t N>
inline __attribute__((always_inline)) void print_exact(const char (&ar)[N])
{
@ -69,10 +75,12 @@ namespace hv {
void print_screen(const span<unsigned char> memory, unsigned long offset)
{
#ifndef FIXED_ROW_SIZE
#define S (const char*)
#define S (2+ROW_SZ)
#define P_EX(n, buf) fwrite(buf, 1, n, stdout)
int ROW_SZ = 24;
#else
#define S
#define P_EX(n, buf) print_exact(buf)
#endif
fmt::print("0x{:016x} ", offset);
char hxbuf[3];
@ -85,7 +93,7 @@ namespace hv {
hxbuf[2] = ' ';
for(;i<memory.size();i++) {
if (i && i % ROW_SZ == 0) { //TODO: Change to i +=16 so we don't have to branch here on every byte. Make sure to not overrun buffer tho
print_exact(r_ascii);
P_EX(S, r_ascii);
fmt::print("\n0x{:016x} ", i+offset); //TODO: Implement this manually then write the buffer with `print_exact`
}
unsigned char idx = memory[i];
@ -101,10 +109,10 @@ namespace hv {
for(std::size_t j=0;j< ROW_SZ - rest;j++)
print_exact(output);
prints(r_ascii);
prints((const char*) r_ascii);
}
else {
print_exact(r_ascii);
P_EX(S, r_ascii);
}
}
}

Loading…
Cancel
Save