[PATCH] LibX11: rm redundant null checks

walter harms wharms at bfs.de
Wed Jun 18 00:51:08 PDT 2014



Am 18.06.2014 00:29, schrieb Peter Hutterer:
> On Sat, Jun 07, 2014 at 11:54:34AM +0200, walter harms wrote:
>>
>> remove more redundant NULL checks
>> note that _XkbFree() is realy Xfree()
>>
>> Signed-off-by: Harms <wharms at bfs,de>
> 
> pushed, with whitespace fixes and a typo fixed. Next time please:
> * make sure the whitespaces match what is used in surrounding code
> * use [PATCH libX11] instead of [PATCH] libX11:, git am will strip out
>   anything between []


ok,
i was not aware of it.
I am pretty happy that the patches apply since this is the first time i used
git this way.
I will not have time for the next weeks but i want to remove a bunch of warnings
as soon i have time again.

re,
 wh



> Cheers,
>    Peter
> 
>> ---
>>  src/GetHints.c      |  2 +-
>>  src/xkb/XKBAlloc.c  |  3 +-
>>  src/xkb/XKBExtDev.c |  6 ++--
>>  src/xkb/XKBGeom.c   | 11 +++---
>>  src/xkb/XKBMAlloc.c | 99 +++++++++++++++++++++++------------------------------
>>  src/xkb/XKBNames.c  |  4 +--
>>  src/xkb/XKBRdBuf.c  |  4 +--
>>  7 files changed, 57 insertions(+), 72 deletions(-)
>>
>> diff --git a/src/GetHints.c b/src/GetHints.c
>> index 513b4b0..f2e1d56 100644
>> --- a/src/GetHints.c
>> +++ b/src/GetHints.c
>> @@ -258,7 +258,7 @@ Status XGetCommand (
>>  	return (0);
>>      }
>>
>> -    if (tp.value) Xfree (tp.value);
>> +    Xfree (tp.value);
>>      *argvp = argv;
>>      *argcp = argc;
>>      return 1;
>> diff --git a/src/xkb/XKBAlloc.c b/src/xkb/XKBAlloc.c
>> index 5cfef0f..50a5764 100644
>> --- a/src/xkb/XKBAlloc.c
>> +++ b/src/xkb/XKBAlloc.c
>> @@ -442,8 +442,7 @@ XkbAllocDeviceInfo(unsigned deviceSpec, unsigned nButtons, unsigned szLeds)
>>              devi->sz_leds = szLeds;
>>              devi->leds = _XkbTypedCalloc(szLeds, XkbDeviceLedInfoRec);
>>              if (!devi->leds) {
>> -                if (devi->btn_acts)
>> -                    _XkbFree(devi->btn_acts);
>> +                _XkbFree(devi->btn_acts);
>>                  _XkbFree(devi);
>>                  return NULL;
>>              }
>> diff --git a/src/xkb/XKBExtDev.c b/src/xkb/XKBExtDev.c
>> index 4065dcd..b9710f8 100644
>> --- a/src/xkb/XKBExtDev.c
>> +++ b/src/xkb/XKBExtDev.c
>> @@ -194,8 +194,8 @@ _XkbReadGetDeviceInfoReply(Display *dpy,
>>          act = &devi->btn_acts[rep->firstBtnWanted];
>>          bzero((char *) act, (rep->nBtnsWanted * sizeof(XkbAction)));
>>      }
>> -    if (devi->name != NULL)
>> -        _XkbFree(devi->name);
>> +
>> +    _XkbFree(devi->name);
>>      if (!_XkbGetReadBufferCountedString(&buf, &devi->name))
>>          goto BAILOUT;
>>      if (rep->nBtnsRtrn > 0) {
>> @@ -475,7 +475,7 @@ _InitLedStuff(SetLedStuff *stuff, unsigned wanted, XkbDeviceInfoPtr devi)
>>  static void
>>  _FreeLedStuff(SetLedStuff * stuff)
>>  {
>> -    if ((stuff->num_info > 0) && (stuff->info != NULL))
>> +    if (stuff->num_info > 0)
>>          _XkbFree(stuff->info);
>>      bzero(stuff, sizeof(SetLedStuff));
>>      return;
>> diff --git a/src/xkb/XKBGeom.c b/src/xkb/XKBGeom.c
>> index feaaab6..66dca9e 100644
>> --- a/src/xkb/XKBGeom.c
>> +++ b/src/xkb/XKBGeom.c
>> @@ -269,10 +269,9 @@ _XkbReadGeomProperties(XkbReadBufferPtr buf,
>>              ok = _XkbGetReadBufferCountedString(buf, &name) && ok;
>>              ok = _XkbGetReadBufferCountedString(buf, &value) && ok;
>>              ok = ok && (XkbAddGeomProperty(geom, name, value) != NULL);
>> -            if (name)
>> -                _XkbFree(name);
>> -            if (value)
>> -                _XkbFree(value);
>> +
>> +	    _XkbFree(name);
>> +	    _XkbFree(value);
>>          }
>>          if (ok)
>>              rtrn = Success;
>> @@ -322,8 +321,8 @@ _XkbReadGeomColors(XkbReadBufferPtr buf,
>>                  rtrn = BadLength;
>>              else if (XkbAddGeomColor(geom, spec, geom->num_colors) == NULL)
>>                  rtrn = BadAlloc;
>> -            if (spec)
>> -                _XkbFree(spec);
>> +
>> +            _XkbFree(spec);
>>              if (rtrn != Success)
>>                  return rtrn;
>>          }
>> diff --git a/src/xkb/XKBMAlloc.c b/src/xkb/XKBMAlloc.c
>> index 61bb413..2e14832 100644
>> --- a/src/xkb/XKBMAlloc.c
>> +++ b/src/xkb/XKBMAlloc.c
>> @@ -226,18 +226,16 @@ XkbCopyKeyType(XkbKeyTypePtr from, XkbKeyTypePtr into)
>>  {
>>      if ((!from) || (!into))
>>          return BadMatch;
>> -    if (into->map) {
>> -        _XkbFree(into->map);
>> -        into->map = NULL;
>> -    }
>> -    if (into->preserve) {
>> -        _XkbFree(into->preserve);
>> -        into->preserve = NULL;
>> -    }
>> -    if (into->level_names) {
>> -        _XkbFree(into->level_names);
>> -        into->level_names = NULL;
>> -    }
>> +
>> +    _XkbFree(into->map);
>> +    into->map = NULL;
>> +
>> +    _XkbFree(into->preserve);
>> +    into->preserve = NULL;
>> +
>> +    _XkbFree(into->level_names);
>> +    into->level_names = NULL;
>> +
>>      *into = *from;
>>      if ((from->map) && (into->map_count > 0)) {
>>          into->map = _XkbTypedCalloc(into->map_count, XkbKTMapEntryRec);
>> @@ -385,11 +383,9 @@ XkbResizeKeyType(XkbDescPtr xkb,
>>      }
>>      type = &xkb->map->types[type_ndx];
>>      if (map_count == 0) {
>> -        if (type->map != NULL)
>> -            _XkbFree(type->map);
>> +        _XkbFree(type->map);
>>          type->map = NULL;
>> -        if (type->preserve != NULL)
>> -            _XkbFree(type->preserve);
>> +        _XkbFree(type->preserve);
>>          type->preserve = NULL;
>>          type->map_count = 0;
>>      }
>> @@ -400,8 +396,7 @@ XkbResizeKeyType(XkbDescPtr xkb,
>>              type->map =
>>                  _XkbTypedRealloc(type->map, map_count, XkbKTMapEntryRec);
>>          if (!type->map) {
>> -            if (prev_map)
>> -                _XkbFree(prev_map);
>> +            _XkbFree(prev_map);
>>              return BadAlloc;
>>          }
>>          if (want_preserve) {
>> @@ -412,12 +407,11 @@ XkbResizeKeyType(XkbDescPtr xkb,
>>                                                    XkbModsRec);
>>              }
>>              if (!type->preserve) {
>> -                if (prev_preserve)
>> -                    _XkbFree(prev_preserve);
>> +                _XkbFree(prev_preserve);
>>                  return BadAlloc;
>>              }
>>          }
>> -        else if (type->preserve != NULL) {
>> +        else {
>>              _XkbFree(type->preserve);
>>              type->preserve = NULL;
>>          }
>> @@ -430,8 +424,7 @@ XkbResizeKeyType(XkbDescPtr xkb,
>>          type->level_names =
>>              _XkbTypedRealloc(type->level_names, new_num_lvls, Atom);
>>          if (!type->level_names) {
>> -            if (prev_level_names)
>> -                _XkbFree(prev_level_names);
>> +            _XkbFree(prev_level_names);
>>              return BadAlloc;
>>          }
>>      }
>> @@ -919,19 +912,17 @@ XkbFreeClientMap(XkbDescPtr xkb, unsigned what, Bool freeMap)
>>                  XkbKeyTypePtr type;
>>
>>                  for (i = 0, type = map->types; i < map->num_types; i++, type++) {
>> -                    if (type->map != NULL) {
>> -                        _XkbFree(type->map);
>> -                        type->map = NULL;
>> -                    }
>> -                    if (type->preserve != NULL) {
>> -                        _XkbFree(type->preserve);
>> -                        type->preserve = NULL;
>> -                    }
>> -                    type->map_count = 0;
>> -                    if (type->level_names != NULL) {
>> -                        _XkbFree(type->level_names);
>> -                        type->level_names = NULL;
>> -                    }
>> +
>> +		  _XkbFree(type->map);
>> +		  type->map = NULL;
>> +
>> +		  _XkbFree(type->preserve);
>> +		  type->preserve = NULL;
>> +
>> +		  type->map_count = 0;
>> +
>> +		  _XkbFree(type->level_names);
>> +		  type->level_names = NULL;
>>                  }
>>              }
>>              _XkbFree(map->types);
>> @@ -940,17 +931,16 @@ XkbFreeClientMap(XkbDescPtr xkb, unsigned what, Bool freeMap)
>>          }
>>      }
>>      if (what & XkbKeySymsMask) {
>> -        if (map->key_sym_map != NULL) {
>> -            _XkbFree(map->key_sym_map);
>> -            map->key_sym_map = NULL;
>> -        }
>> -        if (map->syms != NULL) {
>> -            _XkbFree(map->syms);
>> -            map->size_syms = map->num_syms = 0;
>> -            map->syms = NULL;
>> -        }
>> +
>> +      _XkbFree(map->key_sym_map);
>> +      map->key_sym_map = NULL;
>> +
>> +      _XkbFree(map->syms);
>> +      map->size_syms = map->num_syms = 0;
>> +      map->syms = NULL;
>> +
>>      }
>> -    if ((what & XkbModifierMapMask) && (map->modmap != NULL)) {
>> +    if (what & XkbModifierMapMask) {
>>          _XkbFree(map->modmap);
>>          map->modmap = NULL;
>>      }
>> @@ -971,26 +961,23 @@ XkbFreeServerMap(XkbDescPtr xkb, unsigned what, Bool freeMap)
>>      if (freeMap)
>>          what = XkbAllServerInfoMask;
>>      map = xkb->server;
>> -    if ((what & XkbExplicitComponentsMask) && (map->explicit != NULL)) {
>> +    if (what & XkbExplicitComponentsMask) {
>>          _XkbFree(map->explicit);
>>          map->explicit = NULL;
>>      }
>>      if (what & XkbKeyActionsMask) {
>> -        if (map->key_acts != NULL) {
>> -            _XkbFree(map->key_acts);
>> +           _XkbFree(map->key_acts);
>>              map->key_acts = NULL;
>> -        }
>> -        if (map->acts != NULL) {
>> -            _XkbFree(map->acts);
>> +
>> +           _XkbFree(map->acts);
>>              map->num_acts = map->size_acts = 0;
>> -            map->acts = NULL;
>> -        }
>> +            map->acts = NULL;
>>      }
>> -    if ((what & XkbKeyBehaviorsMask) && (map->behaviors != NULL)) {
>> +    if (what & XkbKeyBehaviorsMask) {
>>          _XkbFree(map->behaviors);
>>          map->behaviors = NULL;
>>      }
>> -    if ((what & XkbVirtualModMapMask) && (map->vmodmap != NULL)) {
>> +    if (what & XkbVirtualModMapMask)  {
>>          _XkbFree(map->vmodmap);
>>          map->vmodmap = NULL;
>>      }
>> diff --git a/src/xkb/XKBNames.c b/src/xkb/XKBNames.c
>> index 5a3fb6f..6c4800c 100644
>> --- a/src/xkb/XKBNames.c
>> +++ b/src/xkb/XKBNames.c
>> @@ -133,8 +133,8 @@ _XkbReadGetNamesReply(Display *dpy,
>>                  if ((nLevels[i] > 0) && (nLevels[i] != type->num_levels)) {
>>                      goto BAILOUT;
>>                  }
>> -                if (type->level_names != NULL)
>> -                    Xfree(type->level_names);
>> +
>> +                Xfree(type->level_names);
>>                  if (nLevels[i] == 0) {
>>                      type->level_names = NULL;
>>                      continue;
>> diff --git a/src/xkb/XKBRdBuf.c b/src/xkb/XKBRdBuf.c
>> index 8e9eab2..9e83f8a 100644
>> --- a/src/xkb/XKBRdBuf.c
>> +++ b/src/xkb/XKBRdBuf.c
>> @@ -167,8 +167,8 @@ _XkbFreeReadBuffer(XkbReadBufferPtr buf)
>>          int left;
>>
>>          left = (int) _XkbReadBufferDataLeft(buf);
>> -        if (buf->start != NULL)
>> -            Xfree(buf->start);
>> +
>> +	Xfree(buf->start);
>>          buf->size = 0;
>>          buf->start = buf->data = NULL;
>>          return left;
>> -- 
>> 1.8.4.5


More information about the xorg-devel mailing list