We must post bugs and squash them***
Edgar Reynaldo

Bugz everywhere!!! I must squash them!

Spot the bug :

for (unsigned int i = (unsigned int)((int)list.size() - 1) ; i >= 0 ; --i) {
   printf("%u\n" , i);
}

;D

MiquelFire

If size() returns 0, then i would be 4 billion (too lazy to look up the number), assuming the cast to unsigned treats negative numbers that way.

I feel like that's not the bug you're asking us to find though.

SiegeLord
#include <SDL2/SDL.h>
#include <SDL2/SDL_timer.h>
 
int main(int argc, char *argv[])
{
    SDL_Init(SDL_INIT_EVERYTHING);
    SDL_Window* win = SDL_CreateWindow("Welcome to SDL",
                                       SDL_WINDOWPOS_CENTERED,
                                       SDL_WINDOWPOS_CENTERED,
                                       1000, 1000, 0);
    SDL_Delay(2000);
}

DarĂ­o B.

When i reaches 0 and it substracts 1, it wraps around to the maximum value of unsigned int. Therefore, the loop never ends.

Peter Hull

GCC knows!

Quote:

<source>:4:43: warning: comparison of unsigned expression in '>= 0' is always true [-Wtype-limits]

(strangely, clang does too but it's not reported, even with -W -Wall)

Elias
SiegeLord said:

SDL_Init(SDL_INIT_EVERYTHING);

Ohhh, can we have al_init_everything()? Instead of:

Maybe with a bonus version that also creates a display and timer and event queue with everything attached, and a call to al_reserve_samples? :D

queue = al_init_everything_ex(1280, 720, 60);
// can get the created display with al_get_current_display()

Erin Maus
#SelectExpand
1#call-to-action button { 2 border: none; 3 outline: none; 4 5 width: 320px; 6 7 font-family: inherit; 8 font-size: 3.5rem; 9 10 color: #eeeeee; 11 text-shadow: 1px 1px #000000; 12 13 background: none; 14 border-image: url('border3.png') 24 24 fill / 24px 24px repeat; 15} 16 17#call-to-action button::before { 18 visibility: hidden; 19 position: absolute; 20 content: url('border3.png') url('border3-hover.png') url('border3-active.png'); 21} 22 23#call-to-action button:hover { 24 color: #ffffff; 25 text-shadow: 1px 1px #000000; 26 27 border-image: url('border3-hover.png') 24 24 fill / 24px 24px repeat; 28} 29 30#call-to-action button:active { 31 color: #dddddd; 32 border-image: url('border3-active.png') 24 24 fill / 24px 24px repeat; 33}

That #call-to-action button::before to prevent image loading when hover/clicked causing a very brief flicker... :-X

DanielH

You can do what I did. I wrapped them up in a function and used flags.

//pseudo code
int init(int flags)
{
    if (!al_init()) return -1
    if (flag & FLAG_IMAGE_ADDON) ...
}

Edgar Reynaldo

The correct code would have been :

for (unsigned int i = list.size() ; i > 0 ; --i) {
   printf("%i\n" , (int)i - 1;
}

It's not often you see underflows, but they're there.

EDIT
Eagle init code (verbatim)

Allegro5System* a5sys = GetAllegro5System();
if (EAGLE_FULL_SETUP != a5sys->Initialize(EAGLE_FULL_SETUP) {
   EagleWarn() << "Not all modules initialized. Warning.\n";
}
EagleGraphicsContext* win = a5sys->CreateGraphicsContext(800,600 , EAGLE_WINDOWED | EAGLE_OPENGL);
if (!(win && win->Valid())) {
   EagleCritical() << "Failed to create window.\n";
}

3 line setup for a window. It serves me right. No more lame queue creation and registration every time you want a window with input. Multiple thread safe windows and more.

Dizzy Egg

;D....Eagle anyone?....no? well ok then.

Edgar Reynaldo

That was not an example of a bug, just init code.

Post your bugs!

Peter Hull

{"name":"612991","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/8\/88c3874f8b5efb365312ba84dabe7fe5.png","w":462,"h":201,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/8\/88c3874f8b5efb365312ba84dabe7fe5"}612991
From the init code of a microcontroller

Edgar Reynaldo

Sweet. Hope that microcontroller didn't do anything important. :D

Polybios
Elias said:

Ohhh, can we have al_init_everything()

Then I also want al_destroy_everything()
>:(

Peter Hull
Polybios said:

Then I also want al_destroy_everything()

That exists but only people above our pay-grade are allowed to used it.

Here's a bit of a shocker that I did not know about until today, from man abs

SYNOPSIS
     #include <stdlib.h>

     int
     abs(int i);

DESCRIPTION
     The abs() function computes the absolute value of the integer i.

RETURN VALUES
     The abs() function returns the absolute value.

So far, so good, but then:

BUGS
     The absolute value of the most negative integer remains negative.


:'(

MiquelFire

That's because signed integers have an extra negative number compared to positive numbers, for example, for an 8 bit value, we have -128 to 127.

Peter Hull

That's because signed integers have an extra negative number compared to positive numbers, for example, for an 8 bit value, we have -128 to 127.

You know this and I know this. But I'm sure I've never written code to account for it

x = abs(x);
if (x >= 0) {
 something(x);
} else {
 error();
}

I don't think there's a better option either, returning zero or INT_MAX or anything else would also lead to silent errors. And C doesn't usually raise a signal for integer arithmetic (? does it?)

MiquelFire

I'm trying to think if a way in which the negative number issue with abs would matter anyway. With signed 8-bit, if -128 is a possible value, what's stopping you from getting -150 before you call abs? I think the times you need to worry about the minimum number being passed to abs, you have to worry about the value being out of range for the integer type you are using anyway.

Thread #618435. Printed from Allegro.cc