gallium/auxiliary: Sanitize NULL checks into canonical form

Use NULL tests of the form `if (ptr)' or `if (!ptr)'.
They do not depend on the definition of the symbol NULL.
Further, they provide the opportunity for the accidental
assignment, are clear and succinct.

Signed-off-by: Edward O'Callaghan <eocallaghan@alterapraxis.com>
Signed-off-by: Marek Olšák <marek.olsak@amd.com>
This commit is contained in:
Edward O'Callaghan 2015-12-04 21:26:50 +11:00 committed by Marek Olšák
parent 147fd00bb3
commit 150c289f60
41 changed files with 61 additions and 61 deletions

View File

@ -247,7 +247,7 @@ struct cso_cache *cso_cache_create(void)
{
struct cso_cache *sc = MALLOC_STRUCT(cso_cache);
int i;
if (sc == NULL)
if (!sc)
return NULL;
sc->max_size = 4096;

View File

@ -244,7 +244,7 @@ static void cso_init_vbuf(struct cso_context *cso)
struct cso_context *cso_create_context( struct pipe_context *pipe )
{
struct cso_context *ctx = CALLOC_STRUCT(cso_context);
if (ctx == NULL)
if (!ctx)
goto out;
ctx->cache = cso_cache_create();
@ -1075,7 +1075,7 @@ cso_single_sampler(struct cso_context *ctx, unsigned shader_stage,
{
void *handle = NULL;
if (templ != NULL) {
if (templ) {
unsigned key_size = sizeof(struct pipe_sampler_state);
unsigned hash_key = cso_construct_key((void*)templ, key_size);
struct cso_hash_iter iter =

View File

@ -72,7 +72,7 @@ draw_create_context(struct pipe_context *pipe, void *context,
boolean try_llvm)
{
struct draw_context *draw = CALLOC_STRUCT( draw_context );
if (draw == NULL)
if (!draw)
goto err_out;
/* we need correct cpu caps for disabling denorms in draw_vbo() */

View File

@ -734,7 +734,7 @@ draw_create_geometry_shader(struct draw_context *draw,
if (use_llvm) {
llvm_gs = CALLOC_STRUCT(llvm_geometry_shader);
if (llvm_gs == NULL)
if (!llvm_gs)
return NULL;
gs = &llvm_gs->base;

View File

@ -551,7 +551,7 @@ draw_llvm_create_variant(struct draw_llvm *llvm,
variant = MALLOC(sizeof *variant +
shader->variant_key_size -
sizeof variant->key);
if (variant == NULL)
if (!variant)
return NULL;
variant->llvm = llvm;
@ -2224,7 +2224,7 @@ draw_gs_llvm_create_variant(struct draw_llvm *llvm,
variant = MALLOC(sizeof *variant +
shader->variant_key_size -
sizeof variant->key);
if (variant == NULL)
if (!variant)
return NULL;
variant->llvm = llvm;

View File

@ -429,7 +429,7 @@ aaline_create_texture(struct aaline_stage *aaline)
PIPE_TRANSFER_WRITE,
&box, &transfer);
if (data == NULL)
if (!data)
return FALSE;
for (i = 0; i < size; i++) {
@ -774,7 +774,7 @@ static struct aaline_stage *
draw_aaline_stage(struct draw_context *draw)
{
struct aaline_stage *aaline = CALLOC_STRUCT(aaline_stage);
if (aaline == NULL)
if (!aaline)
return NULL;
aaline->stage.draw = draw;
@ -824,12 +824,12 @@ aaline_create_fs_state(struct pipe_context *pipe,
struct aaline_stage *aaline = aaline_stage_from_pipe(pipe);
struct aaline_fragment_shader *aafs = NULL;
if (aaline == NULL)
if (!aaline)
return NULL;
aafs = CALLOC_STRUCT(aaline_fragment_shader);
if (aafs == NULL)
if (!aafs)
return NULL;
aafs->state.tokens = tgsi_dup_tokens(fs->tokens);
@ -847,7 +847,7 @@ aaline_bind_fs_state(struct pipe_context *pipe, void *fs)
struct aaline_stage *aaline = aaline_stage_from_pipe(pipe);
struct aaline_fragment_shader *aafs = (struct aaline_fragment_shader *) fs;
if (aaline == NULL) {
if (!aaline) {
return;
}
@ -864,11 +864,11 @@ aaline_delete_fs_state(struct pipe_context *pipe, void *fs)
struct aaline_stage *aaline = aaline_stage_from_pipe(pipe);
struct aaline_fragment_shader *aafs = (struct aaline_fragment_shader *) fs;
if (aafs == NULL) {
if (!aafs) {
return;
}
if (aaline != NULL) {
if (aaline) {
/* pass-through */
aaline->driver_delete_fs_state(pipe, aafs->driver_fs);
@ -889,7 +889,7 @@ aaline_bind_sampler_states(struct pipe_context *pipe, unsigned shader,
assert(start == 0);
if (aaline == NULL) {
if (!aaline) {
return;
}
@ -912,7 +912,7 @@ aaline_set_sampler_views(struct pipe_context *pipe, unsigned shader,
struct aaline_stage *aaline = aaline_stage_from_pipe(pipe);
uint i;
if (aaline == NULL) {
if (!aaline) {
return;
}

View File

@ -662,7 +662,7 @@ static struct aapoint_stage *
draw_aapoint_stage(struct draw_context *draw)
{
struct aapoint_stage *aapoint = CALLOC_STRUCT(aapoint_stage);
if (aapoint == NULL)
if (!aapoint)
goto fail;
aapoint->stage.draw = draw;
@ -707,7 +707,7 @@ aapoint_create_fs_state(struct pipe_context *pipe,
{
struct aapoint_stage *aapoint = aapoint_stage_from_pipe(pipe);
struct aapoint_fragment_shader *aafs = CALLOC_STRUCT(aapoint_fragment_shader);
if (aafs == NULL)
if (!aafs)
return NULL;
aafs->state.tokens = tgsi_dup_tokens(fs->tokens);
@ -767,7 +767,7 @@ draw_install_aapoint_stage(struct draw_context *draw,
* Create / install AA point drawing / prim stage
*/
aapoint = draw_aapoint_stage( draw );
if (aapoint == NULL)
if (!aapoint)
return FALSE;
/* save original driver functions */

View File

@ -915,7 +915,7 @@ static void clip_destroy(struct draw_stage *stage)
struct draw_stage *draw_clip_stage(struct draw_context *draw)
{
struct clip_stage *clipper = CALLOC_STRUCT(clip_stage);
if (clipper == NULL)
if (!clipper)
goto fail;
clipper->stage.draw = draw;

View File

@ -251,7 +251,7 @@ static void cull_destroy( struct draw_stage *stage )
struct draw_stage *draw_cull_stage( struct draw_context *draw )
{
struct cull_stage *cull = CALLOC_STRUCT(cull_stage);
if (cull == NULL)
if (!cull)
goto fail;
cull->stage.draw = draw;

View File

@ -309,7 +309,7 @@ static void flatshade_destroy( struct draw_stage *stage )
struct draw_stage *draw_flatshade_stage( struct draw_context *draw )
{
struct flat_stage *flatshade = CALLOC_STRUCT(flat_stage);
if (flatshade == NULL)
if (!flatshade)
goto fail;
flatshade->stage.draw = draw;

View File

@ -231,7 +231,7 @@ static void offset_destroy( struct draw_stage *stage )
struct draw_stage *draw_offset_stage( struct draw_context *draw )
{
struct offset_stage *offset = CALLOC_STRUCT(offset_stage);
if (offset == NULL)
if (!offset)
goto fail;
offset->stage.draw = draw;

View File

@ -577,7 +577,7 @@ static struct pstip_stage *
draw_pstip_stage(struct draw_context *draw, struct pipe_context *pipe)
{
struct pstip_stage *pstip = CALLOC_STRUCT(pstip_stage);
if (pstip == NULL)
if (!pstip)
goto fail;
pstip->pipe = pipe;
@ -742,7 +742,7 @@ draw_install_pstipple_stage(struct draw_context *draw,
* Create / install pgon stipple drawing / prim stage
*/
pstip = draw_pstip_stage( draw, pipe );
if (pstip == NULL)
if (!pstip)
goto fail;
draw->pipeline.pstipple = &pstip->stage;

View File

@ -235,7 +235,7 @@ stipple_destroy( struct draw_stage *stage )
struct draw_stage *draw_stipple_stage( struct draw_context *draw )
{
struct stipple_stage *stipple = CALLOC_STRUCT(stipple_stage);
if (stipple == NULL)
if (!stipple)
goto fail;
stipple->stage.draw = draw;

View File

@ -165,7 +165,7 @@ static void twoside_destroy( struct draw_stage *stage )
struct draw_stage *draw_twoside_stage( struct draw_context *draw )
{
struct twoside_stage *twoside = CALLOC_STRUCT(twoside_stage);
if (twoside == NULL)
if (!twoside)
goto fail;
twoside->stage.draw = draw;

View File

@ -255,7 +255,7 @@ draw_unfilled_prepare_outputs( struct draw_context *draw,
struct draw_stage *draw_unfilled_stage( struct draw_context *draw )
{
struct unfilled_stage *unfilled = CALLOC_STRUCT(unfilled_stage);
if (unfilled == NULL)
if (!unfilled)
goto fail;
unfilled->stage.draw = draw;

View File

@ -78,7 +78,7 @@ boolean draw_alloc_temp_verts( struct draw_stage *stage, unsigned nr )
unsigned i;
ubyte *store = (ubyte *) MALLOC( MAX_VERTEX_SIZE * nr );
if (store == NULL)
if (!store)
return FALSE;
stage->tmp = (struct vertex_header **) MALLOC( sizeof(struct vertex_header *) * nr );

View File

@ -326,7 +326,7 @@ static void validate_destroy( struct draw_stage *stage )
struct draw_stage *draw_validate_stage( struct draw_context *draw )
{
struct draw_stage *stage = CALLOC_STRUCT(draw_stage);
if (stage == NULL)
if (!stage)
return NULL;
stage->draw = draw;

View File

@ -426,7 +426,7 @@ struct draw_stage *draw_vbuf_stage( struct draw_context *draw,
struct vbuf_render *render )
{
struct vbuf_stage *vbuf = CALLOC_STRUCT(vbuf_stage);
if (vbuf == NULL)
if (!vbuf)
goto fail;
vbuf->stage.draw = draw;

View File

@ -202,7 +202,7 @@ static void wideline_destroy( struct draw_stage *stage )
struct draw_stage *draw_wide_line_stage( struct draw_context *draw )
{
struct wideline_stage *wide = CALLOC_STRUCT(wideline_stage);
if (wide == NULL)
if (!wide)
goto fail;
wide->stage.draw = draw;

View File

@ -315,7 +315,7 @@ static void widepoint_destroy( struct draw_stage *stage )
struct draw_stage *draw_wide_point_stage( struct draw_context *draw )
{
struct widepoint_stage *wide = CALLOC_STRUCT(widepoint_stage);
if (wide == NULL)
if (!wide)
goto fail;
wide->stage.draw = draw;

View File

@ -376,7 +376,7 @@ static void fetch_emit_destroy( struct draw_pt_middle_end *middle )
struct draw_pt_middle_end *draw_pt_fetch_emit( struct draw_context *draw )
{
struct fetch_emit_middle_end *fetch_emit = CALLOC_STRUCT( fetch_emit_middle_end );
if (fetch_emit == NULL)
if (!fetch_emit)
return NULL;
fetch_emit->cache = translate_cache_create();

View File

@ -200,7 +200,7 @@ draw_vs_lookup_variant( struct draw_vertex_shader *vs,
/* Else have to create a new one:
*/
variant = vs->create_variant( vs, key );
if (variant == NULL)
if (!variant)
return NULL;
/* Add it to our list, could be smarter:

View File

@ -225,7 +225,7 @@ draw_create_vs_exec(struct draw_context *draw,
{
struct exec_vertex_shader *vs = CALLOC_STRUCT( exec_vertex_shader );
if (vs == NULL)
if (!vs)
return NULL;
/* we make a private copy of the tokens */

View File

@ -86,7 +86,7 @@ draw_create_vs_llvm(struct draw_context *draw,
{
struct llvm_vertex_shader *vs = CALLOC_STRUCT( llvm_vertex_shader );
if (vs == NULL)
if (!vs)
return NULL;
/* we make a private copy of the tokens */

View File

@ -302,7 +302,7 @@ draw_vs_create_variant_generic( struct draw_vertex_shader *vs,
struct translate_key fetch, emit;
struct draw_vs_variant_generic *vsvg = CALLOC_STRUCT( draw_vs_variant_generic );
if (vsvg == NULL)
if (!vsvg)
return NULL;
vsvg->base.key = *key;

View File

@ -373,7 +373,7 @@ lp_build_const_aos(struct gallivm_state *gallivm,
lp_build_elem_type(gallivm, type);
if(swizzle == NULL)
if (!swizzle)
swizzle = default_swizzle;
elems[swizzle[0]] = lp_build_const_elem(gallivm, type, r);

View File

@ -58,7 +58,7 @@ pp_init(struct pipe_context *pipe, const unsigned int *enabled,
ppq = CALLOC(1, sizeof(struct pp_queue_t));
if (ppq == NULL) {
if (!ppq) {
pp_debug("Unable to allocate memory for ppq.\n");
goto error;
}

View File

@ -238,7 +238,7 @@ pp_jimenezmlaa_init_run(struct pp_queue_t *ppq, unsigned int n,
tmp_text = CALLOC(sizeof(blend2fs_1) + sizeof(blend2fs_2) +
IMM_SPACE, sizeof(char));
if (tmp_text == NULL) {
if (!tmp_text) {
pp_debug("Failed to allocate shader space\n");
return FALSE;
}

View File

@ -262,7 +262,7 @@ pp_tgsi_to_state(struct pipe_context *pipe, const char *text, bool isvs,
*/
tokens = tgsi_alloc_tokens(PP_MAX_TOKENS);
if (tokens == NULL) {
if (!tokens) {
pp_debug("Failed to allocate temporary token storage.\n");
return NULL;
}

View File

@ -321,7 +321,7 @@ iter_instruction(
}
info = tgsi_get_opcode_info( inst->Instruction.Opcode );
if (info == NULL) {
if (!info) {
report_error( ctx, "(%u): Invalid instruction opcode", inst->Instruction.Opcode );
return TRUE;
}

View File

@ -1843,7 +1843,7 @@ ureg_create_with_screen(unsigned processor, struct pipe_screen *screen)
{
int i;
struct ureg_program *ureg = CALLOC_STRUCT( ureg_program );
if (ureg == NULL)
if (!ureg)
goto no_ureg;
ureg->processor = processor;

View File

@ -40,7 +40,7 @@ struct translate_cache {
struct translate_cache * translate_cache_create( void )
{
struct translate_cache *cache = MALLOC_STRUCT(translate_cache);
if (cache == NULL) {
if (!cache) {
return NULL;
}

View File

@ -772,7 +772,7 @@ struct translate *translate_generic_create( const struct translate_key *key )
struct translate_generic *tg = CALLOC_STRUCT(translate_generic);
unsigned i;
if (tg == NULL)
if (!tg)
return NULL;
assert(key->nr_elements <= TRANSLATE_MAX_ATTRIBS);

View File

@ -1486,7 +1486,7 @@ translate_sse2_create(const struct translate_key *key)
goto fail;
p = os_malloc_aligned(sizeof(struct translate_sse), 16);
if (p == NULL)
if (!p)
goto fail;
memset(p, 0, sizeof(*p));

View File

@ -107,7 +107,7 @@ util_draw_texquad(struct pipe_context *pipe, struct cso_context *cso,
float *v = NULL;
v = MALLOC(vertexBytes);
if (v == NULL)
if (!v)
goto out;
/*

View File

@ -289,7 +289,7 @@ pipe_buffer_map_range(struct pipe_context *pipe,
u_box_1d(offset, length, &box);
map = pipe->transfer_map(pipe, buffer, 0, access, &box, transfer);
if (map == NULL) {
if (!map) {
return NULL;
}

View File

@ -24,7 +24,7 @@ struct util_ringbuffer
struct util_ringbuffer *util_ringbuffer_create( unsigned dwords )
{
struct util_ringbuffer *ring = CALLOC_STRUCT(util_ringbuffer);
if (ring == NULL)
if (!ring)
return NULL;
assert(util_is_power_of_two(dwords));

View File

@ -80,7 +80,7 @@ util_make_vertex_passthrough_shader_with_so(struct pipe_context *pipe,
uint i;
ureg = ureg_create( TGSI_PROCESSOR_VERTEX );
if (ureg == NULL)
if (!ureg)
return NULL;
if (window_space)
@ -228,7 +228,7 @@ util_make_fragment_tex_shader_writemask(struct pipe_context *pipe,
interp_mode == TGSI_INTERPOLATE_PERSPECTIVE);
ureg = ureg_create( TGSI_PROCESSOR_FRAGMENT );
if (ureg == NULL)
if (!ureg)
return NULL;
sampler = ureg_DECL_sampler( ureg, 0 );
@ -298,7 +298,7 @@ util_make_fragment_tex_shader_writedepth(struct pipe_context *pipe,
struct ureg_src imm;
ureg = ureg_create( TGSI_PROCESSOR_FRAGMENT );
if (ureg == NULL)
if (!ureg)
return NULL;
sampler = ureg_DECL_sampler( ureg, 0 );
@ -350,7 +350,7 @@ util_make_fragment_tex_shader_writedepthstencil(struct pipe_context *pipe,
struct ureg_src imm;
ureg = ureg_create( TGSI_PROCESSOR_FRAGMENT );
if (ureg == NULL)
if (!ureg)
return NULL;
depth_sampler = ureg_DECL_sampler( ureg, 0 );
@ -414,7 +414,7 @@ util_make_fragment_tex_shader_writestencil(struct pipe_context *pipe,
struct ureg_src imm;
ureg = ureg_create( TGSI_PROCESSOR_FRAGMENT );
if (ureg == NULL)
if (!ureg)
return NULL;
stencil_sampler = ureg_DECL_sampler( ureg, 0 );
@ -494,7 +494,7 @@ void *
util_make_empty_fragment_shader(struct pipe_context *pipe)
{
struct ureg_program *ureg = ureg_create(TGSI_PROCESSOR_FRAGMENT);
if (ureg == NULL)
if (!ureg)
return NULL;
ureg_END(ureg);
@ -518,7 +518,7 @@ util_make_fragment_cloneinput_shader(struct pipe_context *pipe, int num_cbufs,
assert(num_cbufs <= PIPE_MAX_COLOR_BUFS);
ureg = ureg_create( TGSI_PROCESSOR_FRAGMENT );
if (ureg == NULL)
if (!ureg)
return NULL;
src = ureg_DECL_fs_input( ureg, input_semantic, 0,
@ -848,7 +848,7 @@ util_make_geometry_passthrough_shader(struct pipe_context *pipe,
unsigned i;
ureg = ureg_create(TGSI_PROCESSOR_GEOMETRY);
if (ureg == NULL)
if (!ureg)
return NULL;
ureg_property(ureg, TGSI_PROPERTY_GS_INPUT_PRIM, PIPE_PRIM_POINTS);

View File

@ -37,7 +37,7 @@ void u_default_transfer_inline_write( struct pipe_context *pipe,
level,
usage,
box, &transfer);
if (map == NULL)
if (!map)
return;
if (resource->target == PIPE_BUFFER) {

View File

@ -270,7 +270,7 @@ void u_upload_buffer(struct u_upload_mgr *upload,
PIPE_TRANSFER_READ,
&transfer);
if (map == NULL) {
if (!map) {
pipe_resource_reference(outbuf, NULL);
return;
}

View File

@ -542,7 +542,7 @@ vl_mpeg12_get_decode_buffer(struct vl_mpeg12_decoder *dec, struct pipe_video_buf
return buffer;
buffer = CALLOC_STRUCT(vl_mpeg12_buffer);
if (buffer == NULL)
if (!buffer)
return NULL;
if (!vl_vb_init(&buffer->vertex_stream, dec->context,