Skip to content
Snippets Groups Projects

Simplify cmpack

Open Hanicef requested to merge Hanicef/SRB2:simplify-cmpack into next

In an attempt to try to track down a second form of chatbug (I can both confirm that !2238 (merged) fixed the most serious type of chatbug, and that there are more variants, based on the extended testing I've done since that patch was merged), I noticed that cmpack was a bit overcomplicated, so I simplified it.

Test code used to verify the function:

#include <stdio.h>

typedef int INT32;
typedef unsigned char UINT8;
typedef signed char SINT8;

// return <0 if a < b (mod 256)
//         0 if a = n (mod 256)
//        >0 if a > b (mod 256)
// mnemonic: to use it compare to 0: cmpack(a,b)<0 is "a < b" ...
static INT32 cmpack(UINT8 a, UINT8 b)
{
	return (SINT8)(a - b);
}

int main(void)
{
	printf("%d\n", cmpack(1, 1));
	printf("%d\n", cmpack(1, 2));
	printf("%d\n", cmpack(2, 1));
	printf("%d\n", cmpack(1, 254));
	printf("%d\n", cmpack(254, 2));
}

Compile with gcc -O2 -fwrapv for proper testing.

NOTE: This is low-priority and can wait, I only did it because it feels nice to simplify code.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Loading
  • Loading
  • Loading
Please register or sign in to reply
Loading