Articles

Checking whether a pointer is valid in Linux

Recently I noticed some calls I was making to a certain C API were returning pointers that I thought were invalid. A quick inspection with gdb confirmed my fears. A particular interaction showed:

(gdb) print *job->someMember
Cannot access memory at address 0xec00000005

Unfortunately I don’t have access to ...







Please, don’t use exit(-1)

DISCLAIMER: There are lots of code that use the very function call I’m going to criticize in this post, so take my opinion with a grain of salt (even though I believe I’m right.)

Introduction

In the past two weeks I saw a few cases where programmers were ...