ronantakizawa/codereview-bench huggingface dataset:
Repository: libsdl-org/SDL
File: src/video/SDL_bmp.c (C)

Code before:
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    int alphaChannelOffset = 0;
#else
    int alphaChannelOffset = 3;
#endif
    Uint8 *alpha = ((Uint8 *)surface->pixels) + alphaChannelOffset;
    Uint8 *end = alpha + surface->h * surface->pitch;

    while (alpha < end) {
        if (*alpha != 0) {
            hasAlpha = true;
            break;
        }
        alpha += 4;
    }

    if (!hasAlpha) {
        alpha = ((Uint8 *)surface->pixels) + alphaChannelOffset;
        while (alpha < end) {
            *alpha = SDL_ALPHA_OPAQUE;
            alpha += 4;
        }
    }
}

bool SDL_IsBMP(SDL_IOStream* src)
{
    Sint64 start;
    Uint8 magic[2];
    bool is_BMP;

    is_BMP = false;
    start = SDL_TellIO(src);
    if (start >= 0) {
        if (SDL_ReadIO(src, magic, sizeof(magic)) == sizeof(magic)) {
            if (magic[0] == 'B' && magic[1] == 'M') {
                is_BMP = true;
            }
        }
        SDL_SeekIO(src, start, SDL_IO_SEEK_SET);
    }

    return is_BMP;
}

SDL_Surface *SDL_LoadBMP_IO(SDL_IOStream *src, bool closeio)
{
    bool was_error = true;
    Sint64 fp_offset = 0;
    int i, pad;
    SDL_Surface *surface;

Review comment (suggestion):
```suggestion
bool SDL_IsBMP(SDL_IOStream *src)
```

Code after:
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    int alphaChannelOffset = 0;
#else
    int alphaChannelOffset = 3;
#endif
    Uint8 *alpha = ((Uint8 *)surface->pixels) + alphaChannelOffset;
    Uint8 *end = alpha + surface->h * surface->pitch;

    while (alpha < end) {
        if (*alpha != 0) {
            hasAlpha = true;
            break;
        }
        alpha += 4;
    }

    if (!hasAlpha) {
        alpha = ((Uint8 *)surface->pixels) + alphaChannelOffset;
        while (alpha < end) {
            *alpha = SDL_ALPHA_OPAQUE;
            alpha += 4;
        }
    }
}

bool SDL_IsBMP(SDL_IOStream *src)
{
    Sint64 start;
    Uint8 magic[2];
    bool is_BMP;

    is_BMP = false;
    start = SDL_TellIO(src);
    if (start >= 0) {
        if (SDL_ReadIO(src, magic, sizeof(magic)) == sizeof(magic)) {
            if (magic[0] == 'B' && magic[1] == 'M') {
                is_BMP = true;
            }
        }
        SDL_SeekIO(src, start, SDL_IO_SEEK_SET);
    }

    return is_BMP;
}

SDL_Surface *SDL_LoadBMP_IO(SDL_IOStream *src, bool closeio)
{
    bool was_error = true;
    Sint64 fp_offset = 0;
    int i, pad;
    SDL_Surface *surface;
Repository: libsdl-org/SDL
File: src/video/SDL_stb.c (C)

Code before:
                for (col = 0; col < w; ++col) {
                    Uint8 c = *src_ptr++;
                    Uint8 a = *src_ptr++;
                    *dst++ = c;
                    *dst++ = c;
                    *dst++ = c;
                    *dst++ = a;
                }
                dst += skip;
            }
            stbi_image_free(pixels);
        }
    } else {
        SDL_SetError("Unknown image format: %d", format);
    }

    if (!surface) {
        /* The error message should already be set */
        stbi_image_free(pixels); /* calls SDL_free() */
        SDL_SeekIO(src, start, SDL_IO_SEEK_SET);
    }
    return surface;
}
#endif // SDL_HAVE_STB

bool SDL_IsPNG(SDL_IOStream* src)
{
    Sint64 start;
    Uint8 magic[4];
    bool is_PNG;

    is_PNG = false;
    start = SDL_TellIO(src);
    if (start >= 0) {
        if (SDL_ReadIO(src, magic, sizeof(magic)) == sizeof(magic)) {
            if (magic[0] == 0x89 &&
                magic[1] == 'P' &&
                magic[2] == 'N' &&
                magic[3] == 'G') {
                is_PNG = true;
            }
        }
        SDL_SeekIO(src, start, SDL_IO_SEEK_SET);
    }

    return is_PNG;
}

SDL_Surface *SDL_LoadPNG_IO(SDL_IOStream *src, bool closeio)
{
    SDL_Surface *surface = NULL;

Review comment (suggestion):
```suggestion
bool SDL_IsPNG(SDL_IOStream *src)
```

Code after:
                for (col = 0; col < w; ++col) {
                    Uint8 c = *src_ptr++;
                    Uint8 a = *src_ptr++;
                    *dst++ = c;
                    *dst++ = c;
                    *dst++ = c;
                    *dst++ = a;
                }
                dst += skip;
            }
            stbi_image_free(pixels);
        }
    } else {
        SDL_SetError("Unknown image format: %d", format);
    }

    if (!surface) {
        /* The error message should already be set */
        stbi_image_free(pixels); /* calls SDL_free() */
        SDL_SeekIO(src, start, SDL_IO_SEEK_SET);
    }
    return surface;
}
#endif // SDL_HAVE_STB

bool SDL_IsPNG(SDL_IOStream *src)
{
    Sint64 start;
    Uint8 magic[4];
    bool is_PNG;

    is_PNG = false;
    start = SDL_TellIO(src);
    if (start >= 0) {
        if (SDL_ReadIO(src, magic, sizeof(magic)) == sizeof(magic)) {
            if (magic[0] == 0x89 &&
                magic[1] == 'P' &&
                magic[2] == 'N' &&
                magic[3] == 'G') {
                is_PNG = true;
            }
        }
        SDL_SeekIO(src, start, SDL_IO_SEEK_SET);
    }

    return is_PNG;
}

SDL_Surface *SDL_LoadPNG_IO(SDL_IOStream *src, bool closeio)
{
    SDL_Surface *surface = NULL;
Repository: libsdl-org/SDL
File: src/core/linux/SDL_udev.c (C)

Code before:
    val = _this->syms.udev_device_get_property_value(dev, "ID_REVISION");
    if (val) {
        inpid->version = (Uint16)SDL_strtol(val, NULL, 16);
    }

    if (driver) {
        val = _this->syms.udev_device_get_driver(dev);
        if (!val) {
            val = _this->syms.udev_device_get_property_value(dev, "ID_USB_DRIVER");
        }
        if (val) {
            *driver = SDL_strdup(val);
        }
    }

    class_temp = device_class(dev);
    if (class_temp) {
        *class = class_temp;
    }

    _this->syms.udev_device_unref(dev);

    return true;
}

bool SDL_UDEV_GetProductSerial(const char *device_path,const char **serial)
{
    struct stat statbuf;
    char type;
    struct udev_device *dev;
    const char *val;
    int class_temp;

    if (!_this) {
        return false;
    }

    if (stat(device_path, &statbuf) == -1) {
        return false;
    }

    if (S_ISBLK(statbuf.st_mode)) {
        type = 'b';
    }
    else if (S_ISCHR(statbuf.st_mode)) {
        type = 'c';
    }
    else {
        return false;
    }


Review comment (suggestion):
```suggestion
bool SDL_UDEV_GetProductSerial(const char *device_path, const char **serial)
```

Code after:
    val = _this->syms.udev_device_get_property_value(dev, "ID_REVISION");
    if (val) {
        inpid->version = (Uint16)SDL_strtol(val, NULL, 16);
    }

    if (driver) {
        val = _this->syms.udev_device_get_driver(dev);
        if (!val) {
            val = _this->syms.udev_device_get_property_value(dev, "ID_USB_DRIVER");
        }
        if (val) {
            *driver = SDL_strdup(val);
        }
    }

    class_temp = device_class(dev);
    if (class_temp) {
        *class = class_temp;
    }

    _this->syms.udev_device_unref(dev);

    return true;
}

bool SDL_UDEV_GetProductSerial(const char *device_path, const char **serial)
{
    struct stat statbuf;
    char type;
    struct udev_device *dev;
    const char *val;

    if (!_this) {
        return false;
    }

    if (stat(device_path, &statbuf) < 0) {
        return false;
    }

    if (S_ISBLK(statbuf.st_mode)) {
        type = 'b';
    } else if (S_ISCHR(statbuf.st_mode)) {
        type = 'c';
    } else {
        return false;
    }

    dev = _this->syms.udev_device_new_from_devnum(_this->udev, type, statbuf.st_rdev);
    if (!dev) {
        return false;
Repository: libsdl-org/SDL
File: src/core/linux/SDL_udev.c (C)

Code before:
        }
    }

    class_temp = device_class(dev);
    if (class_temp) {
        *class = class_temp;
    }

    _this->syms.udev_device_unref(dev);

    return true;
}

bool SDL_UDEV_GetProductSerial(const char *device_path,const char **serial)
{
    struct stat statbuf;
    char type;
    struct udev_device *dev;
    const char *val;
    int class_temp;

    if (!_this) {
        return false;
    }

    if (stat(device_path, &statbuf) == -1) {
        return false;
    }

    if (S_ISBLK(statbuf.st_mode)) {
        type = 'b';
    }
    else if (S_ISCHR(statbuf.st_mode)) {
        type = 'c';
    }
    else {
        return false;
    }

    dev = _this->syms.udev_device_new_from_devnum(_this->udev, type, statbuf.st_rdev);

    if (!dev) {
        return false;
    }

    val = _this->syms.udev_device_get_property_value(dev, "ID_SERIAL_SHORT");
    if (val) {
        *serial = val;
        return true;
    }


Review comment (suggestion):
```suggestion
    if (stat(device_path, &statbuf) < 0) {
```

Code after:
        }
    }

    class_temp = device_class(dev);
    if (class_temp) {
        *class = class_temp;
    }

    _this->syms.udev_device_unref(dev);

    return true;
}

bool SDL_UDEV_GetProductSerial(const char *device_path, const char **serial)
{
    struct stat statbuf;
    char type;
    struct udev_device *dev;
    const char *val;

    if (!_this) {
        return false;
    }

    if (stat(device_path, &statbuf) < 0) {
        return false;
    }

    if (S_ISBLK(statbuf.st_mode)) {
        type = 'b';
    } else if (S_ISCHR(statbuf.st_mode)) {
        type = 'c';
    } else {
        return false;
    }

    dev = _this->syms.udev_device_new_from_devnum(_this->udev, type, statbuf.st_rdev);
    if (!dev) {
        return false;
    }

    val = _this->syms.udev_device_get_property_value(dev, "ID_SERIAL_SHORT");
    if (val) {
        *serial = val;
        return true;
    }

    return false;
}

void SDL_UDEV_UnloadLibrary(void)
Repository: libsdl-org/SDL
File: src/core/linux/SDL_udev.c (C)

Code before:
    return true;
}

bool SDL_UDEV_GetProductSerial(const char *device_path,const char **serial)
{
    struct stat statbuf;
    char type;
    struct udev_device *dev;
    const char *val;
    int class_temp;

    if (!_this) {
        return false;
    }

    if (stat(device_path, &statbuf) == -1) {
        return false;
    }

    if (S_ISBLK(statbuf.st_mode)) {
        type = 'b';
    }
    else if (S_ISCHR(statbuf.st_mode)) {
        type = 'c';
    }
    else {
        return false;
    }

    dev = _this->syms.udev_device_new_from_devnum(_this->udev, type, statbuf.st_rdev);

    if (!dev) {
        return false;
    }

    val = _this->syms.udev_device_get_property_value(dev, "ID_SERIAL_SHORT");
    if (val) {
        *serial = val;
        return true;
    }

    serial = NULL;
    return false;
}

void SDL_UDEV_UnloadLibrary(void)
{
    if (!_this) {
        return;
    }


Review comment (suggestion):
```suggestion
    } else if (S_ISCHR(statbuf.st_mode)) {
        type = 'c';
    } else {
```

Code after:
    return true;
}

bool SDL_UDEV_GetProductSerial(const char *device_path, const char **serial)
{
    struct stat statbuf;
    char type;
    struct udev_device *dev;
    const char *val;

    if (!_this) {
        return false;
    }

    if (stat(device_path, &statbuf) < 0) {
        return false;
    }

    if (S_ISBLK(statbuf.st_mode)) {
        type = 'b';
    } else if (S_ISCHR(statbuf.st_mode)) {
        type = 'c';
    } else {
        return false;
    }

    dev = _this->syms.udev_device_new_from_devnum(_this->udev, type, statbuf.st_rdev);
    if (!dev) {
        return false;
    }

    val = _this->syms.udev_device_get_property_value(dev, "ID_SERIAL_SHORT");
    if (val) {
        *serial = val;
        return true;
    }

    return false;
}

void SDL_UDEV_UnloadLibrary(void)
{
    if (!_this) {
        return;
    }

    if (_this->udev_handle) {
        SDL_UnloadObject(_this->udev_handle);
        _this->udev_handle = NULL;
    }
}
Repository: libsdl-org/SDL
File: src/core/linux/SDL_udev.c (C)

Code before:
        return false;
    }

    if (S_ISBLK(statbuf.st_mode)) {
        type = 'b';
    }
    else if (S_ISCHR(statbuf.st_mode)) {
        type = 'c';
    }
    else {
        return false;
    }

    dev = _this->syms.udev_device_new_from_devnum(_this->udev, type, statbuf.st_rdev);

    if (!dev) {
        return false;
    }

    val = _this->syms.udev_device_get_property_value(dev, "ID_SERIAL_SHORT");
    if (val) {
        *serial = val;
        return true;
    }

    serial = NULL;
    return false;
}

void SDL_UDEV_UnloadLibrary(void)
{
    if (!_this) {
        return;
    }

    if (_this->udev_handle) {
        SDL_UnloadObject(_this->udev_handle);
        _this->udev_handle = NULL;
    }
}

bool SDL_UDEV_LoadLibrary(void)
{
    bool result = true;

    if (!_this) {
        return SDL_SetError("UDEV not initialized");
    }

    // See if there is a udev library already loaded
    if (SDL_UDEV_load_syms()) {

Review comment (suggestion):
```suggestion
    *serial = NULL;
```
Actually we should do this at the top of the function so it's set before any `return false` statements. In this particular case it's not a public API and we know we're not going to use the value on a false return, so we can probably omit this.

Code after:
    }

    if (S_ISBLK(statbuf.st_mode)) {
        type = 'b';
    } else if (S_ISCHR(statbuf.st_mode)) {
        type = 'c';
    } else {
        return false;
    }

    dev = _this->syms.udev_device_new_from_devnum(_this->udev, type, statbuf.st_rdev);
    if (!dev) {
        return false;
    }

    val = _this->syms.udev_device_get_property_value(dev, "ID_SERIAL_SHORT");
    if (val) {
        *serial = val;
        return true;
    }

    return false;
}

void SDL_UDEV_UnloadLibrary(void)
{
    if (!_this) {
        return;
    }

    if (_this->udev_handle) {
        SDL_UnloadObject(_this->udev_handle);
        _this->udev_handle = NULL;
    }
}

bool SDL_UDEV_LoadLibrary(void)
{
    bool result = true;

    if (!_this) {
        return SDL_SetError("UDEV not initialized");
    }

    // See if there is a udev library already loaded
    if (SDL_UDEV_load_syms()) {
        return true;
    }

#ifdef SDL_UDEV_DYNAMIC
    // Check for the build environment's libudev first
Repository: libsdl-org/SDL
File: src/core/linux/SDL_udev.h (C/C++)

Code before:
    void (*udev_unref)(struct udev *);
    struct udev_device *(*udev_device_new_from_devnum)(struct udev *udev, char type, dev_t devnum);
    dev_t (*udev_device_get_devnum)(struct udev_device *udev_device);
} SDL_UDEV_Symbols;

typedef struct SDL_UDEV_PrivateData
{
    const char *udev_library;
    SDL_SharedObject *udev_handle;
    struct udev *udev;
    struct udev_monitor *udev_mon;
    int ref_count;
    SDL_UDEV_CallbackList *first, *last;

    // Function pointers
    SDL_UDEV_Symbols syms;
} SDL_UDEV_PrivateData;

extern bool SDL_UDEV_Init(void);
extern void SDL_UDEV_Quit(void);
extern void SDL_UDEV_UnloadLibrary(void);
extern bool SDL_UDEV_LoadLibrary(void);
extern void SDL_UDEV_Poll(void);
extern bool SDL_UDEV_Scan(void);
extern bool SDL_UDEV_GetProductInfo(const char *device_path, struct input_id *inpid, int *class, char **driver);
extern bool SDL_UDEV_GetProductSerial(const char *device_path,const char **serial);
extern bool SDL_UDEV_AddCallback(SDL_UDEV_Callback cb);
extern void SDL_UDEV_DelCallback(SDL_UDEV_Callback cb);
extern const SDL_UDEV_Symbols *SDL_UDEV_GetUdevSyms(void);
extern void SDL_UDEV_ReleaseUdevSyms(void);

#endif // HAVE_LIBUDEV_H && HAVE_LINUX_INPUT_H

#endif // SDL_udev_h_


Review comment (suggestion):
```suggestion
extern bool SDL_UDEV_GetProductSerial(const char *device_path, const char **serial);
```

Code after:
    void (*udev_unref)(struct udev *);
    struct udev_device *(*udev_device_new_from_devnum)(struct udev *udev, char type, dev_t devnum);
    dev_t (*udev_device_get_devnum)(struct udev_device *udev_device);
} SDL_UDEV_Symbols;

typedef struct SDL_UDEV_PrivateData
{
    const char *udev_library;
    SDL_SharedObject *udev_handle;
    struct udev *udev;
    struct udev_monitor *udev_mon;
    int ref_count;
    SDL_UDEV_CallbackList *first, *last;

    // Function pointers
    SDL_UDEV_Symbols syms;
} SDL_UDEV_PrivateData;

extern bool SDL_UDEV_Init(void);
extern void SDL_UDEV_Quit(void);
extern void SDL_UDEV_UnloadLibrary(void);
extern bool SDL_UDEV_LoadLibrary(void);
extern void SDL_UDEV_Poll(void);
extern bool SDL_UDEV_Scan(void);
extern bool SDL_UDEV_GetProductInfo(const char *device_path, struct input_id *inpid, int *class, char **driver);
extern bool SDL_UDEV_GetProductSerial(const char *device_path, const char **serial);
extern bool SDL_UDEV_AddCallback(SDL_UDEV_Callback cb);
extern void SDL_UDEV_DelCallback(SDL_UDEV_Callback cb);
extern const SDL_UDEV_Symbols *SDL_UDEV_GetUdevSyms(void);
extern void SDL_UDEV_ReleaseUdevSyms(void);

#endif // HAVE_LIBUDEV_H && HAVE_LINUX_INPUT_H

#endif // SDL_udev_h_
Repository: libsdl-org/SDL
File: src/main/SDL_main_callbacks.c (C)

Code before:
    }
    SDL_DispatchMainCallbackEvents();

    SDL_AppResult rc = (SDL_AppResult)SDL_GetAtomicInt(&apprc);
    if (rc == SDL_APP_CONTINUE) {
        rc = SDL_main_iteration_callback(SDL_main_appstate);
        if (!SDL_CompareAndSwapAtomicInt(&apprc, SDL_APP_CONTINUE, rc)) {
            rc = (SDL_AppResult)SDL_GetAtomicInt(&apprc); // something else already set a quit result, keep that.
        }
    }
    return rc;
}

void SDL_QuitMainCallbacks(SDL_AppResult result)
{
    SDL_RemoveEventWatch(SDL_MainCallbackEventWatcher, NULL);
    SDL_main_quit_callback(SDL_main_appstate, result);
    SDL_main_appstate = NULL;  // just in case.

    // for symmetry, you should explicitly Quit what you Init, but we might come through here uninitialized and SDL_Quit() will clear everything anyhow.
    //SDL_QuitSubSystem(SDL_INIT_EVENTS);

    SDL_Quit();
}

void SDL_CheckDefaultArgcArgv(int *_argc, char ***_argv)
{
    if (!_argv)
    {
        static char dummyargv0[] = { 'S', 'D', 'L', '_', 'a', 'p', 'p', '\0' };
        static char *argvdummy[2] = { dummyargv0, NULL };
        *_argc = 1;
        *_argv = argvdummy;
    }
}


Review comment (suggestion):
```suggestion
void SDL_CheckDefaultArgcArgv(int *argc, char ***argv)
```

Code after:
    }
    SDL_DispatchMainCallbackEvents();

    SDL_AppResult rc = (SDL_AppResult)SDL_GetAtomicInt(&apprc);
    if (rc == SDL_APP_CONTINUE) {
        rc = SDL_main_iteration_callback(SDL_main_appstate);
        if (!SDL_CompareAndSwapAtomicInt(&apprc, SDL_APP_CONTINUE, rc)) {
            rc = (SDL_AppResult)SDL_GetAtomicInt(&apprc); // something else already set a quit result, keep that.
        }
    }
    return rc;
}

void SDL_QuitMainCallbacks(SDL_AppResult result)
{
    SDL_RemoveEventWatch(SDL_MainCallbackEventWatcher, NULL);
    SDL_main_quit_callback(SDL_main_appstate, result);
    SDL_main_appstate = NULL;  // just in case.

    // for symmetry, you should explicitly Quit what you Init, but we might come through here uninitialized and SDL_Quit() will clear everything anyhow.
    //SDL_QuitSubSystem(SDL_INIT_EVENTS);

    SDL_Quit();
}

void SDL_CheckDefaultArgcArgv(int *argc, char ***argv)
{
    if (!argv)
    {
        static char dummyargv0[] = { 'S', 'D', 'L', '_', 'a', 'p', 'p', '\0' };
        static char *argvdummy[2] = { dummyargv0, NULL };
        *argc = 1;
        *argv = argvdummy;
    }
}
Repository: libsdl-org/SDL
File: src/video/haiku/SDL_bmodes.cc (C++)

Code before:
bool HAIKU_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect)
{
    BScreen bscreen;
    BRect rc = bscreen.Frame();
    rect->x = (int)rc.left;
    rect->y = (int)rc.top;
    rect->w = (int)rc.Width() + 1;
    rect->h = (int)rc.Height() + 1;
    return true;
}

bool HAIKU_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display)
{
    // Get the current screen
    BScreen bscreen;

    // Iterate through all of the modes
    SDL_DisplayMode mode;
    display_mode this_bmode;
    display_mode *bmodes;
    uint32 count, i;

    // Get graphics-hardware supported modes
    bscreen.GetModeList(&bmodes, &count);
    bscreen.GetMode(&this_bmode);

    for (i = 0; i < count; ++i) {
        // FIXME: Apparently there are errors with colorspace changes
        if (bmodes[i].space == this_bmode.space) {
            _BDisplayModeToSdlDisplayMode(&bmodes[i], &mode);
            SDL_AddFullscreenDisplayMode(display, &mode);
        }
    }
    free(bmodes); // This should NOT be SDL_free()
    return true;
}


bool HAIKU_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
{
    // Get the current screen
    BScreen bscreen;
    if (!bscreen.IsValid()) {
        return SDL_SetError("Invalid screen");
    }

    // Set the mode using the driver data
    display_mode *bmode = _ExtractBMode(mode);


    // FIXME: Is the first option always going to be the right one?

Review comment (suggestion):
```suggestion
    if (bscreen.GetModeList(&bmodes, &count) == B_OK) {
```

Code after:
bool HAIKU_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect)
{
    BScreen bscreen;
    BRect rc = bscreen.Frame();
    rect->x = (int)rc.left;
    rect->y = (int)rc.top;
    rect->w = (int)rc.Width() + 1;
    rect->h = (int)rc.Height() + 1;
    return true;
}

bool HAIKU_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display)
{
    // Get the current screen
    BScreen bscreen;

    // Iterate through all of the modes
    SDL_DisplayMode mode;
    display_mode this_bmode;
    display_mode *bmodes;
    uint32 count, i;
    bool r = false;

    // Get graphics-hardware supported modes
    if (bscreen.GetModeList(&bmodes, &count) == B_OK)
    {
        if (bscreen.GetMode(&this_bmode) == B_OK)
        {
            for (i = 0; i < count; ++i) {
                // FIXME: Apparently there are errors with colorspace changes
                if (bmodes[i].space == this_bmode.space) {
                    _BDisplayModeToSdlDisplayMode(&bmodes[i], &mode);
                    SDL_AddFullscreenDisplayMode(display, &mode);
                }
            }
            r = true;
        }
        free(bmodes); // This should NOT be SDL_free()
    }

    return r;
}


bool HAIKU_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
{
    // Get the current screen
    BScreen bscreen;
    if (!bscreen.IsValid()) {
        return SDL_SetError("Invalid screen");
    }