Reversing bits in C (on ARM)

August 8, 2013

I wrote a blog post over on the Square Engineering Blog about efficiently reversing bits on ARM.  It even got picked up by Reddit, where readers pointed out some corrections :)

Check it out!

0

Stupid C++ Tricks: A better sizeof_array()

January 23, 2011

The tried-and-true C way to determine the length of an array is this:

#define sizeof_array(x) (sizeof(x) / sizeof(x[0]))

As H. L. Mencken put it, “there is always a well-known solution to every human problem — neat, plausible, and wrong.” That is certainly the case with this approach. It’s short, to the point, very easy to understand, and insidiously error-prone.

This traditional sizeof_array() implementation commits a cardinal offense of compiled, statically-typed programming languages. It can be given seemingly-correct input, not give any warnings or errors, and emit completely random garbage into your executable. Let’s take a closer look at it, and see if we can do better.
(more…)

6

hax0red

January 17, 2011

A few months ago, I noticed that cnicholson.net was serving a blank page, and that Google Chrome was warning me of malware. I sent an email to Dreamhost asking if things were ok, and they responded with a link to their Troubleshooting Hacked Sites wiki page. Uh oh. I let the site languish because work was busy and my personal life was more important. Just yesterday I devoted a few hours to figuring out what was going on, and fixing it. Fortunately this was pretty fun, and I got to brush up on my GNU tools. Read on for the gory details.
(more…)

2

Stupid C++ Tricks: do/while(0) and C4127

March 1, 2009
Tags: , , , ,

A nice little quickie:  I briefly discuss in my assert ramblings why it’s important to wrap all of your multi-line macros in do/while(0) blocks.  An unfortunate side-effect of this is that the construction

// NOISY CODE
#define MULTI_LINE_MACRO \
	do { \
		std::printf("Hello "); \
		std::printf("world!\n"); \
	} while (0)

will trigger C4127: “Conditional expression is constant” in Visual Studio 2003/2005, and probably 2008 as well (but I haven’t tried it).  The culprit is the “while(0)” part, the compiler thinks we’re making a mistake when of course this is all very intentional. Let’s see what we can do to fix it!
(more…)

19

Fun With iPhone Emoji

February 15, 2009
Tags: ,

OK, before we begin, I want to make sure we’re all iPhone-toting hipsters here. We love the visual voicemail, and all the lifestyle-enabling apps like Facebook, Shazam, Amazon.com, and the AP News Wire. The games are great, too.

Texting, however, leaves a little to be desired. The conversations are threaded, which is all well and good, but there’s no MMS anywhere to be found. There aren’t even emoticons anywhere either, so we all send ASCII smileys back and forth: “:)” “:(” “;-)” “:-D” “X-[” and so on.

Japan leapfrogged us on this one. Evidently most Japanese cell phones come with Emoji, which is a reserved set of the Unicode character space exclusively for emoticons!
(more…)

0

Stupid C++ Tricks: Adventures in Assert

February 10, 2009

This is a re-hosting of the original Assert article I wrote in April 2007,  during the epic rise and fall of Power of Two Games.  I’m reprinting it here on my personal site now that Pow2 is defunct and expired. Of the few reasons we failed, the lack of a good assert macro was not one of them!

(more…)

18