Sorted Arrays...



  • I'm amazed at some of the code I have to maintain.  Before today I thought insertion on a sorted array was a simple operation.

    while ( i < total && !done)
    {
        if( data[i] < new )
            i++;
        else
        {
            temp = malloc( (total+1) * sizeof(short) );
            memset(temp,0,sizeof(temp));
            strcpy(temp,&data[i]);
            data[i] = new;
            strcpy(&data[i+1],temp);
            done = 1;
            free(temp);
        }
    }
    if(!done)
        data[total]= new;
    
    There's almost as many WTFs in that as semicolons.


  • This, ladies and gentlemen, is what we call a WTF.  The Real WTF here is the code, if you'll indulge me.

    There are management WTFs and there are design WTFs and there are WTFs that emerge out of ego and idiocy, but this WTF brings a tear to my eye because it is the purest form of the WTF: coding without having any clue what you're doing.



  • @omega0 said:

            strcpy(temp,&data[i]);
    data[i] = new;
    strcpy(&data[i+1],temp);

    Please tell me they're not trying to copy an array of shorts with strcpy...

    somebody?

    please? 

    cries

     



  • That'll be fun when there's a number lower than 256 in it :)

     



  • @aihtdikh said:

    @omega0 said:
            strcpy(temp,&data[i]);
    data[i] = new;
    strcpy(&data[i+1],temp);

    Please tell me they're not trying to copy an array of shorts with strcpy...

    somebody?

    please? 

    cries

     

    Have the Police been notified of attempted (and probable) Buffer Overflow?

    Computers don't like it.   http://xkcd.com/371/



  • My favorite part is where they memset(temp, 0, sizeof(void*)), or whatever temp's type is.


Log in to reply