public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: "Érico Nogueira" <ericonr@disroot.org>
To: "Mark Wielaard" <mark@klomp.org>, "Martin Liška" <mliska@suse.cz>,
	elfutils-devel@sourceware.org
Subject: Re: [PATCH] RFC: come up with startswith function.
Date: Tue, 20 Apr 2021 08:50:11 -0300	[thread overview]
Message-ID: <560469fa-70df-e37e-73d6-a046d8f3cebd@disroot.org> (raw)
In-Reply-To: <12db7aec12ccccd7a4aff4114cc7c3887d81073d.camel@klomp.org>



Em 20/04/2021 08:43, Mark Wielaard escreveu:
> Hi Martin,
> 
> On Mon, 2021-04-19 at 15:18 +0200, Martin Liška wrote:
>> I made similar changes to binutils some time ago and I would like to
>> come up with the same function for elfutils. Note that current
>> construct
>> is quite error prone, I found for instance these 2 bad usages:
>>
>> diff --git a/libdwfl/relocate.c b/libdwfl/relocate.c
>> index 88b5211d..b6de3510 100644
>> --- a/libdwfl/relocate.c
>> +++ b/libdwfl/relocate.c
>> @@ -518,7 +518,7 @@ relocate_section (Dwfl_Module *mod, Elf
>> *relocated, const GElf_Ehdr *ehdr,
>>          Nothing to do here.  */
>>       return DWFL_E_NOERROR;
>>   
>> -  if (strncmp (tname, ".zdebug", strlen ("zdebug")) == 0)
>> +  if (strncmp (tname, ".zdebug", strlen (".zdebug")) == 0)
>>       elf_compress_gnu (tscn, 0, 0);
>>   
>>     if ((tshdr->sh_flags & SHF_COMPRESSED) != 0)
>> @@ -539,7 +539,7 @@ relocate_section (Dwfl_Module *mod, Elf
>> *relocated, const GElf_Ehdr *ehdr,
>>     if (sname == NULL)
>>       return DWFL_E_LIBELF;
>>   
>> -  if (strncmp (sname, ".zdebug", strlen ("zdebug")) == 0)
>> +  if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0)
>>       elf_compress_gnu (scn, 0, 0);
>>   
>>     if ((shdr->sh_flags & SHF_COMPRESSED) != 0)
> 
> Urgh. Thanks for finding this!
> 
>> I'm not convinced about function declaration in system.h. Is it a
>> proper location?
> 
> Yes, I think it is.
> 
>> And the function is not used in debuginfod/debuginfod-client.c and
>> debuginfod/debuginfod.cxx.
>> I would need another decl for these, am I right?
> 
> I think they both can simply include system.h (might want to double
> check the -I search path in debuginfod/Makefile.am) because system.h
> should be stand-alone, you don't need to link to anything else.
> 
> Maybe for debuginfod.cxx there is a better C++ way for strings. But if
> it uses C strings, then it could also simply include system.h.

std::basic_string_view::starts_with is only C++20, so I'd suggest 
wrapping `startswith` to not have to type `.c_str()` all the time, but 
nothing beyond that.

> 
> Thanks,
> 
> Mark
> 

  reply	other threads:[~2021-04-20 11:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-19 13:18 Martin Liška
2021-04-20 11:43 ` Mark Wielaard
2021-04-20 11:50   ` Érico Nogueira [this message]
2021-04-21  7:13   ` Martin Liška
2021-04-30 22:13     ` Mark Wielaard
2021-05-10 13:26       ` Martin Liška
2021-05-12 10:01         ` Mark Wielaard
2021-05-12 10:24           ` Martin Liška

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=560469fa-70df-e37e-73d6-a046d8f3cebd@disroot.org \
    --to=ericonr@disroot.org \
    --cc=elfutils-devel@sourceware.org \
    --cc=mark@klomp.org \
    --cc=mliska@suse.cz \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).