From: Kuan-Wei Chiu <visitorckw@gmail.com>
To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
namhyung@kernel.org
Cc: mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com,
kan.liang@linux.intel.com, jserv@ccns.ncku.edu.tw,
chuang@cs.nycu.edu.tw, dave@stgolabs.net,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] perf bench: Fix undefined behavior in cmpworker()
Date: Tue, 10 Dec 2024 07:24:13 +0800 [thread overview]
Message-ID: <Z1d8HVO4gXench5V@visitorckw-System-Product-Name> (raw)
In-Reply-To: <20241209145728.1975311-1-visitorckw@gmail.com>
On Mon, Dec 09, 2024 at 10:57:28PM +0800, Kuan-Wei Chiu wrote:
> The comparison function cmpworker() does not comply with the C
> standard's requirements for qsort() comparison functions. Specifically,
> it returns 0 when w1->tid < w2->tid, which is incorrect. According to
> the standard, the function must return a negative value in such cases
> to preserve proper ordering.
>
> This violation causes undefined behavior, potentially leading to issues
> such as memory corruption in certain versions of glibc [1].
>
> Fix the issue by returning -1 when w1->tid < w2->tid, ensuring
> compliance with the C standard and preventing undefined behavior.
>
I reviewed my commit message again and thought it might be clearer to
explicitly mention, as in the previous patch, that the issue stems from
violating symmetry and transitivity. The current cmpworker() can result
in x > y but y = x, leading to undefined behavior. I'll wait for review
comments before updating the patch description.
Regards,
Kuan-Wei
prev parent reply other threads:[~2024-12-09 23:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-09 14:57 [PATCH] perf bench: Fix undefined behavior in cmpworker() Kuan-Wei Chiu
2024-12-09 23:24 ` Kuan-Wei Chiu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z1d8HVO4gXench5V@visitorckw-System-Product-Name \
--to=visitorckw@gmail.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=chuang@cs.nycu.edu.tw \
--cc=dave@stgolabs.net \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=jserv@ccns.ncku.edu.tw \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox