Skip to contentSkip to conversation

sizeof (struct tYpO *) : it is just a typo or rather a bug ?

DISCUSSION Toralf Förster 4 participants 10 messages Jul 24, 2014 – Jul 29, 2014

lore
Share & tools
lore
#0 lore raw

Inspired by this "typo" fix
http://article.gmane.org/gmane.linux.kernel/1754640
I grep'ed the current git tree of linus for similar issues.

For these 4 places I'm wondering where the appropriate struct definition is located :

arch/ia64/sn/kernel/io_acpi_init.c: sizeof(struct pci_devdev_info *)) {

tools/perf/builtin-sched.c:     sched->tasks = realloc(sched->tasks, sched->nr_tasks * sizeof(struct task_task *));
fs/ceph/xattr.c:                xattrs = kcalloc(numattr, sizeof(struct ceph_xattr *),
fs/ceph/xattr.c:                memset(xattrs, 0, numattr*sizeof(struct ceph_xattr *));

Nevertheless I was told, that gcc doesn't complain about such things due to eventually evaluating it to "sizeof(null)". I'm however curious if at least a warning should be emitted in such a case, or?

Signature · 1 line
Toralf
#1 lore raw
Quoted 10 lines · Toralf Förster

Inspired by this "typo" fix
http://article.gmane.org/gmane.linux.kernel/1754640
I grep'ed the current git tree of linus for similar issues.

For these 4 places I'm wondering where the appropriate struct definition is located :

arch/ia64/sn/kernel/io_acpi_init.c: sizeof(struct pci_devdev_info *)) {

tools/perf/builtin-sched.c:     sched->tasks = realloc(sched->tasks, sched->nr_tasks * sizeof(struct task_task *));
fs/ceph/xattr.c:                xattrs = kcalloc(numattr, sizeof(struct ceph_xattr *),
fs/ceph/xattr.c:                memset(xattrs, 0, numattr*sizeof(struct ceph_xattr *));

Heh, the ceph one is a five year old typo.. Looks like it should be struct ceph_inode_xattr, I'll fix it up. I'm curious though, how did you grep for these?

Thanks,

Ilya

#2 lore raw
Quoted 12 lines · Ilya Dryomov
Quoted 10 lines · Toralf Förster

Inspired by this "typo" fix
http://article.gmane.org/gmane.linux.kernel/1754640
I grep'ed the current git tree of linus for similar issues.

For these 4 places I'm wondering where the appropriate struct definition is located :

arch/ia64/sn/kernel/io_acpi_init.c: sizeof(struct pci_devdev_info *)) {

tools/perf/builtin-sched.c:     sched->tasks = realloc(sched->tasks, sched->nr_tasks * sizeof(struct task_task *));
fs/ceph/xattr.c:                xattrs = kcalloc(numattr, sizeof(struct ceph_xattr *),
fs/ceph/xattr.c:                memset(xattrs, 0, numattr*sizeof(struct ceph_xattr *));
Quoted 8 lines

Heh, the ceph one is a five year old typo.. Looks like it should be struct ceph_inode_xattr, I'll fix it up. I'm curious though, how did you grep for these?

Thanks,

Ilya

1:

	grep -Hr "sizeof[ *(]struct .* \*.)"  | cut -f2- -d':' | tee ~/tmp/out

2:

	cat ~/tmp/out | perl -wane 'chomp(); my ($left, $right) = split (/sizeof\(/); print $right, "\n";' | cut -f2 -d' ' | sort -u | cut -f1 -d')' | grep -v '^+' | while read i; do echo $i; git grep -q "struct $i {" || echo error; echo; done

3:
ignore false positives

Signature · 1 line
Toralf
#3 lore raw
In reply to Toralf Förster
Quoted 3 lines · Toralf Förster

Inspired by this "typo" fix
http://article.gmane.org/gmane.linux.kernel/1754640
I grep'ed the current git tree of linus for similar issues.

I wonder if we couldn't use Coccinelle to do that? I would say it would be not as cool as deep grep magick, but Coccinelle is cool by definition and therefore immune from any such comparisons :-)

Quoted 3 lines

Nevertheless I was told, that gcc doesn't complain about such things due to eventually evaluating it to "sizeof(null)". I'm however curious if at least a warning should be emitted in such a case, or?

Well, it cannot become a real bug because the moment the code changes to actually access/derreference such a typo, it will cause the compiler to abort with an error. If gcc will have to waste a measurable amount of time to issue such a warning, it is not worth it.

OTOH, such typos could confuse someone reading the code into thinking they're dealing with a different structure or something, and it _is_ incorrect code no matter how harmless, so it makes sense to fix all such typos eventually.

Signature · 8 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh
--
To unsubscribe from this list: send the line "unsubscribe linux-ia64" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw

Hi Dear cocci,

may I forward to you this email from the LKML, Henrique thinks, that that issue worth a coccinelle patch :-D

-------- Original Message --------
Subject: Re: sizeof (struct tYpO *) : it is just a typo or rather a bug ?
Date: Fri, 25 Jul 2014 08:20:39 -0300
From: Henrique de Moraes Holschuh <[email protected]>
To: Toralf F?rster <[email protected]>
CC: linux-ia64 at vger.kernel.org, ceph-devel at vger.kernel.org, Linux Kernel <[email protected]>

Quoted 3 lines · Toralf F?rster

Inspired by this "typo" fix
http://article.gmane.org/gmane.linux.kernel/1754640
I grep'ed the current git tree of linus for similar issues.

I wonder if we couldn't use Coccinelle to do that? I would say it would be not as cool as deep grep magick, but Coccinelle is cool by definition and therefore immune from any such comparisons :-)

Quoted 3 lines

Nevertheless I was told, that gcc doesn't complain about such things due to eventually evaluating it to "sizeof(null)". I'm however curious if at least a warning should be emitted in such a case, or?

Well, it cannot become a real bug because the moment the code changes to actually access/derreference such a typo, it will cause the compiler to abort with an error. If gcc will have to waste a measurable amount of time to issue such a warning, it is not worth it.

OTOH, such typos could confuse someone reading the code into thinking they're dealing with a different structure or something, and it _is_ incorrect code no matter how harmless, so it makes sense to fix all such typos eventually.

Signature · 4 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh
#5 lore raw

Thanks for the forward. It should be possible to do something with Coccinelle.

How did you use grep, though?

julia

Quoted 49 lines · Toralf F?rster

Hi Dear cocci,

may I forward to you this email from the LKML, Henrique thinks, that that issue worth a coccinelle patch :-D

-------- Original Message --------
Subject: Re: sizeof (struct tYpO *) : it is just a typo or rather a bug ?
Date: Fri, 25 Jul 2014 08:20:39 -0300
From: Henrique de Moraes Holschuh <[email protected]>
To: Toralf F?rster <[email protected]>
CC: linux-ia64 at vger.kernel.org, ceph-devel at vger.kernel.org, Linux Kernel <[email protected]>

Quoted 3 lines · Toralf F?rster

Inspired by this "typo" fix
http://article.gmane.org/gmane.linux.kernel/1754640
I grep'ed the current git tree of linus for similar issues.

I wonder if we couldn't use Coccinelle to do that? I would say it would be not as cool as deep grep magick, but Coccinelle is cool by definition and therefore immune from any such comparisons :-)

Quoted 3 lines

Nevertheless I was told, that gcc doesn't complain about such things due to eventually evaluating it to "sizeof(null)". I'm however curious if at least a warning should be emitted in such a case, or?

Well, it cannot become a real bug because the moment the code changes to actually access/derreference such a typo, it will cause the compiler to abort with an error. If gcc will have to waste a measurable amount of time to issue such a warning, it is not worth it.

OTOH, such typos could confuse someone reading the code into thinking they're dealing with a different structure or something, and it _is_ incorrect code no matter how harmless, so it makes sense to fix all such typos eventually.

Signature · 11 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh



_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
#6 lore raw
Quoted 7 lines · Julia Lawall

Thanks for the forward. It should be possible to do something with Coccinelle.

How did you use grep, though?

julia

1:

	grep -Hr "sizeof[ *(]struct .* \*.)"  | cut -f2- -d':' | tee ~/tmp/out

2:

	cat ~/tmp/out | perl -wane 'chomp(); my ($left, $right) = split (/sizeof\(/); print $right, "\n";' | cut -f2 -d' ' | sort -u | cut -f1 -d')' | grep -v '^+' | while read i; do echo $i; git grep -q "struct $i {" || echo error; echo; done

3:
ignore false positives

Quoted 50 lines · Toralf F?rster
Quoted 49 lines

Hi Dear cocci,

may I forward to you this email from the LKML, Henrique thinks, that that issue worth a coccinelle patch :-D

-------- Original Message --------
Subject: Re: sizeof (struct tYpO *) : it is just a typo or rather a bug ?
Date: Fri, 25 Jul 2014 08:20:39 -0300
From: Henrique de Moraes Holschuh <[email protected]>
To: Toralf F?rster <[email protected]>
CC: linux-ia64 at vger.kernel.org, ceph-devel at vger.kernel.org, Linux Kernel <[email protected]>

Quoted 3 lines · Toralf F?rster

Inspired by this "typo" fix
http://article.gmane.org/gmane.linux.kernel/1754640
I grep'ed the current git tree of linus for similar issues.

I wonder if we couldn't use Coccinelle to do that? I would say it would be not as cool as deep grep magick, but Coccinelle is cool by definition and therefore immune from any such comparisons :-)

Quoted 3 lines

Nevertheless I was told, that gcc doesn't complain about such things due to eventually evaluating it to "sizeof(null)". I'm however curious if at least a warning should be emitted in such a case, or?

Well, it cannot become a real bug because the moment the code changes to actually access/derreference such a typo, it will cause the compiler to abort with an error. If gcc will have to waste a measurable amount of time to issue such a warning, it is not worth it.

OTOH, such typos could confuse someone reading the code into thinking they're dealing with a different structure or something, and it _is_ incorrect code no matter how harmless, so it makes sense to fix all such typos eventually.

Signature · 11 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh



_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
Signature · 1 line
Toralf
#7 lore raw
Quoted 8 lines · Toralf F?rster
Quoted 7 lines · Julia Lawall

Thanks for the forward. It should be possible to do something with Coccinelle.

How did you use grep, though?

julia

Quoted 8 lines

1:

	grep -Hr "sizeof[ *(]struct .* \*.)"  | cut -f2- -d':' | tee ~/tmp/out

2:

	cat ~/tmp/out | perl -wane 'chomp(); my ($left, $right) = split (/sizeof\(/); print $right, "\n";' | cut -f2 -d' ' | sort -u | cut -f1 -d')' | grep -v '^+' | while read i; do echo $i; git grep -q "struct $i {" || echo error; echo; done

3:
ignore false positives

OK :)

julia

Quoted 58 lines
Quoted 52 lines · Toralf F?rster
Quoted 49 lines

Hi Dear cocci,

may I forward to you this email from the LKML, Henrique thinks, that that issue worth a coccinelle patch :-D

-------- Original Message --------
Subject: Re: sizeof (struct tYpO *) : it is just a typo or rather a bug ?
Date: Fri, 25 Jul 2014 08:20:39 -0300
From: Henrique de Moraes Holschuh <[email protected]>
To: Toralf F?rster <[email protected]>
CC: linux-ia64 at vger.kernel.org, ceph-devel at vger.kernel.org, Linux Kernel <[email protected]>

Quoted 3 lines · Toralf F?rster

Inspired by this "typo" fix
http://article.gmane.org/gmane.linux.kernel/1754640
I grep'ed the current git tree of linus for similar issues.

I wonder if we couldn't use Coccinelle to do that? I would say it would be not as cool as deep grep magick, but Coccinelle is cool by definition and therefore immune from any such comparisons :-)

Quoted 3 lines

Nevertheless I was told, that gcc doesn't complain about such things due to eventually evaluating it to "sizeof(null)". I'm however curious if at least a warning should be emitted in such a case, or?

Well, it cannot become a real bug because the moment the code changes to actually access/derreference such a typo, it will cause the compiler to abort with an error. If gcc will have to waste a measurable amount of time to issue such a warning, it is not worth it.

OTOH, such typos could confuse someone reading the code into thinking they're dealing with a different structure or something, and it _is_ incorrect code no matter how harmless, so it makes sense to fix all such typos eventually.

Signature · 11 lines
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh



_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
Signature · 1 line
Toralf
#8 lore raw
Quoted 3 lines · Julia Lawall

OK :)

julia

Hi
;)

BTW, 3 of the 4 mentioned places I found in the kernel sources with that procedure were confirmed to be real errors - 1 feedback is still awaiting.

Signature · 1 line
Toralf
#9 lore raw

This is clearly a typo:

drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c

        vpfe_dev->clks = kzalloc(vpfe_cfg->num_clocks *
                                   sizeof(struct clock *), GFP_KERNEL);

I also found:

fs/reiserfs/resize.c

                copy_size =
                    copy_size * sizeof(struct reiserfs_list_bitmap_node *);

and

drivers/net/ethernet/intel/i40e/i40e_main.c

                size = sizeof(struct i40e_q_vectors *) * vsi->num_q_vectors;

but I'm not sure about them. Also some other results that I haven't had a chance to look at yet.

julia

Quoted 15 lines · Toralf F?rster
Quoted 3 lines · Julia Lawall

OK :)

julia

Hi
;)

BTW, 3 of the 4 mentioned places I found in the kernel sources with that procedure were confirmed to be real errors - 1 feedback is still awaiting.

Signature · 1 line
Toralf