Bug 52993 - gomp_init_nest_lock_25: possible bad call to memset
Summary: gomp_init_nest_lock_25: possible bad call to memset
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libgomp (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-15 10:52 UTC by David Binderman
Modified: 2012-06-14 17:46 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-04-24 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Binderman 2012-04-15 10:52:45 UTC
I just tried to analyse the source code of gcc-4.8 trunk
dated 20120415 with the latest cppcheck-1.54.

It said

[libgomp/config/linux/lock.c:178]: (warning) Using size of pointer lock instead
of size of its data.

Source code is

void
gomp_init_nest_lock_25 (omp_nest_lock_25_t *lock)
{
  memset (lock, 0, sizeof (lock));
}

Maybe better is

void
gomp_init_nest_lock_25 (omp_nest_lock_25_t *lock)
{
  memset (lock, 0, sizeof (*lock));
}
Comment 1 Andrew Pinski 2012-04-24 04:32:17 UTC
For LP64I32 targets, the code will most likely just work correctly as the struct will be two ints which is the same size as one pointer.

While for LPI32 targets, it will be broken.  So confirmed.
Comment 2 Jakub Jelinek 2012-06-06 18:31:13 UTC
Author: jakub
Date: Wed Jun  6 18:31:06 2012
New Revision: 188276

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=188276
Log:
	PR libgomp/52993
	* config/linux/lock.c (gomp_init_nest_lock_25): Fix up last
	argument to memset call.

Modified:
    trunk/libgomp/ChangeLog
    trunk/libgomp/config/linux/lock.c
Comment 3 Jakub Jelinek 2012-06-06 18:32:45 UTC
Not a big deal, since this is a Linux only file, and on Linux LIBGOMP_GNU_SYMBOL_VERSIONING should be defined, therefore the code isn't compiled in.  Fixed onthe trunk anyway, not worth backporting.
Comment 4 Jakub Jelinek 2012-06-14 17:46:57 UTC
Author: jakub
Date: Thu Jun 14 17:46:53 2012
New Revision: 188624

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=188624
Log:
	Backported from mainline
	2012-06-06  Jakub Jelinek  <jakub@redhat.com>

	PR libgomp/52993
	* config/linux/lock.c (gomp_init_nest_lock_25): Fix up last
	argument to memset call.

Modified:
    branches/gcc-4_7-branch/libgomp/ChangeLog
    branches/gcc-4_7-branch/libgomp/config/linux/lock.c