mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-02 09:40:15 +00:00
ncblit_*(): sanity check linesize parameter
This commit is contained in:
parent
2bb546e3ac
commit
07cc29634f
@ -833,6 +833,9 @@ int ncblit_bgrx(const void* data, int linesize, const struct ncvisual_options* v
|
||||
if(vopts->flags > NCVISUAL_OPTION_BLEND){
|
||||
return -1;
|
||||
}
|
||||
if(linesize <= 0 || (size_t)linesize < vopts->lenx * sizeof(uint32_t)){
|
||||
return -1;
|
||||
}
|
||||
struct ncplane* nc = vopts->n;
|
||||
if(nc == NULL){
|
||||
return -1;
|
||||
@ -872,6 +875,9 @@ int ncblit_rgba(const void* data, int linesize, const struct ncvisual_options* v
|
||||
if(vopts->flags > NCVISUAL_OPTION_BLEND){
|
||||
return -1;
|
||||
}
|
||||
if(linesize <= 0 || (size_t)linesize < vopts->lenx * sizeof(uint32_t)){
|
||||
return -1;
|
||||
}
|
||||
struct ncplane* nc = vopts->n;
|
||||
if(nc == NULL){
|
||||
return -1;
|
||||
|
@ -59,14 +59,12 @@ auto bgra_to_rgba(const void* data, int rows, int rowstride, int cols) -> void*
|
||||
if(rowstride % 4){ // must be a multiple of 4 bytes
|
||||
return nullptr;
|
||||
}
|
||||
//fprintf(stderr, "ROWS: %d\n", rows);
|
||||
auto ret = static_cast<uint32_t*>(malloc(rowstride * rows));
|
||||
if(ret){
|
||||
for(int y = 0 ; y < rows ; ++y){
|
||||
for(int x = 0 ; x < cols ; ++x){
|
||||
const uint32_t* src = (const uint32_t*)data + (rowstride / 4) * y + x;
|
||||
uint32_t* dst = ret + (rowstride / 4) * y + x;
|
||||
//fprintf(stderr, "SRC: %x DST: %x\n", *src, *dst);
|
||||
*dst = ((*src & 0xff00u) << 16u) | (*src & 0xff00ffu) | ((*src & 0xff000000) >> 16u);
|
||||
//fprintf(stderr, "y: %d x: %d SRC: %x DST: %x\n", y, x, *src, *dst);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user