source: rtems/cpukit/score/src/objectsetname.c @ fce900b5

5
Last change on this file since fce900b5 was ed4c556, checked in by Joel Sherrill <joel.sherrill@…>, on 11/20/14 at 23:25:15

objectsetname.c: Fix always true condition (Coverity ID 1063874)

Coverity spotted the comparison (0 <= length) which is always true.
Changed logic to address this.

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/**
2 * @file
3 *
4 * @brief Set Objects Name
5 * @ingroup ScoreObject
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2014.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#ifdef HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/score/objectimpl.h>
22#include <rtems/score/wkspace.h>
23
24#include <string.h>
25
26bool _Objects_Set_name(
27  Objects_Information *information,
28  Objects_Control     *the_object,
29  const char          *name
30)
31{
32  size_t                 length;
33  const char            *s;
34
35  s      = name;
36  length = strnlen( name, information->name_length );
37
38#if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
39  if ( information->is_string ) {
40    char *d;
41
42    d = _Workspace_Allocate( length + 1 );
43    if ( !d )
44      return false;
45
46    _Workspace_Free( (void *)the_object->name.name_p );
47    the_object->name.name_p = NULL;
48
49    strncpy( d, name, length );
50    d[length] = '\0';
51    the_object->name.name_p = d;
52  } else
53#endif
54  {
55    the_object->name.name_u32 =  _Objects_Build_name(
56      ((length)     ? s[ 0 ] : ' '),
57      ((length > 1) ? s[ 1 ] : ' '),
58      ((length > 2) ? s[ 2 ] : ' '),
59      ((length > 3) ? s[ 3 ] : ' ')
60    );
61
62  }
63
64  return true;
65}
Note: See TracBrowser for help on using the repository browser.