Author Topic: Some weird C Pointers  (Read 3711 times)

0 Members and 1 Guest are viewing this topic.

Offline msuffidyTopic starter

  • Frequent Contributor
  • **
  • Posts: 270
  • Country: ca
Some weird C Pointers
« on: April 01, 2026, 11:08:49 pm »
I am trying to compile this little pad thing that lets you make phone calls in linux to bluetooth phones like iphones. It is not compiling and may be a change in syntax from earlier gcc. I can kind of force it to compile but then it crashes. I have not proven this part of the program is making it crash but I think it is likely. So The line of concern is:

 if (tail) { *tail = q.tail; }

Code: [Select]
[In file included from ../include/libhfp/bt.h:30,
                 from hfpd.cpp:30:
../include/libhfp/list.h: In static member function ‘static void libhfp::SListRadixSort<CompFunc>::Sort(libhfp::SListItem&, libhfp::SListItem*, param_t)’:
../include/libhfp/list.h:1019:39: error: no match for ‘operator=’ (operand types are ‘libhfp::SListItem’ and ‘libhfp::SListItem*’) [-Wtemplate-body]
 1019 |                 if (tail) { *tail = q.tail; }
      |                                       ^~~~
../include/libhfp/list.h:1019:39: note: there is 1 candidate
../include/libhfp/list.h:766:27: note: candidate 1: ‘libhfp::SListItem& libhfp::SListItem::operator=(libhfp::SListItem&)’
  766 |         inline SListItem &operator=(SListItem &)
      |                           ^~~~~~~~
../include/libhfp/list.h:766:37: note: no known conversion for argument 1 from ‘libhfp::SListItem*’ to ‘libhfp::SListItem&’
  766 |         inline SListItem &operator=(SListItem &)
      |                                     ^~~~~~~~~~~
/code]
 

Offline msuffidyTopic starter

  • Frequent Contributor
  • **
  • Posts: 270
  • Country: ca
Re: Some weird C Pointers
« Reply #1 on: April 01, 2026, 11:28:51 pm »
I think the idea is you are supposed to alter the memory at &tail with the q.tail contents. Maybe you could do that with some sort of memcopy instead of =? I got it to compile by just removing *tail = to tail =.
 

Offline msuffidyTopic starter

  • Frequent Contributor
  • **
  • Posts: 270
  • Country: ca
Re: Some weird C Pointers
« Reply #2 on: April 02, 2026, 12:51:36 am »
The program seems to be dying before getting to this point so maybe there is another problem.
 

Online golden_labels

  • Super Contributor
  • ***
  • Posts: 2439
  • Country: pl
Re: Some weird C Pointers
« Reply #3 on: April 02, 2026, 01:44:09 am »
This is C++, not C.

The affected portion of code is undocumented and also happily circumvents logic of other objects to overwrite their innards. Quickly grasping author’s intentions is therefore hard.

My first guess, without analyzing the code fully, is that the tail parameter is meant to (optionally) reference list’s tail member for overwriting. So it is meant to be SListItem** instead of SListItem*.


I think the idea is you are supposed to alter the memory at &tail with the q.tail contents. Maybe you could do that with some sort of memcopy instead of =?
Using memmove to circumvent type system and force compiler to “shut up” on a correct error? As if memmove in C++ wasn’t already questionable in most circumstances, that idea can be summed up as: I don’t understand this situation, so let’s just bulldoze over it — maybe the compiler will stop bothering me. No, this is not how this works. Forget about such ideas for the rest of your life.
« Last Edit: April 02, 2026, 02:07:22 am by golden_labels »
Why 📎 | We live in times when half of people have IQ below 100.
 

Offline msuffidyTopic starter

  • Frequent Contributor
  • **
  • Posts: 270
  • Country: ca
Re: Some weird C Pointers
« Reply #4 on: April 02, 2026, 01:49:02 am »
Well right now I am pursuing compiling the QT5 version on a Linux VM of an earlier version of linux and seeing if the binary still runs on my version. I'd call that a success if it does. Thanks
 

Offline msuffidyTopic starter

  • Frequent Contributor
  • **
  • Posts: 270
  • Country: ca
Re: Some weird C Pointers
« Reply #5 on: April 02, 2026, 02:41:08 am »
Well it did compile but it crashes the same way so I don't know. Not looking good beyond debugging the source.

hfstandalone: hfstandalone.cpp:545: void RealUI::SetDeviceBox(AgDevice*, AgDevice::CallControlMode, QString&, QString&, QString&): Assertion `status != NULL' failed.
Aborted                    (core dumped) padsp hfstandalone
« Last Edit: April 02, 2026, 02:43:15 am by msuffidy »
 

Offline msuffidyTopic starter

  • Frequent Contributor
  • **
  • Posts: 270
  • Country: ca
Re: Some weird C Pointers
« Reply #6 on: April 02, 2026, 03:11:18 am »
OK So I got it working. Actually when I upgraded my Fedora from 38 to 43 I still have some old files. I just used the binary from that set and it works.

I made a few conclusions that I guess were not true.
no1) I selected the QT5 git branch thinking it was working. It is possible it was never working in the first place.
no2) It was my impression that lower QT versions were not supported anymore but they are in fact.

So I just installed some more packages and the binary found a missing libQt3Support.so.4. Whatever it works.
So in this recording I did not record the microphone and did not optimize the buffers. The spin off is you can record phone conversations.
« Last Edit: April 02, 2026, 03:36:36 am by msuffidy »
 

Offline msuffidyTopic starter

  • Frequent Contributor
  • **
  • Posts: 270
  • Country: ca
Re: Some weird C Pointers
« Reply #7 on: April 02, 2026, 03:52:01 am »
uh well I tried compiling the default git on fedora 43 and got that same error but I did this:

if (tail) { memcpy(&tail,q.tail,sizeof(tail)); }

and it seems to work.

**A day later and thinking about it and what it probably means is

if (tail) { memcpy(tail,&q.tail,sizeof(tail)); }

**So far messing with this line does not seem to affect how the program runs mostly.
I think the point is *pointer = value means modify memory at pointer (data) with value, not make pointer a=b and not use the address pointed to b but at b. So yes I was playing forcing the compiler.
That is to say the dereference aspect means to modify the thing a pointer is pointer is pointing to as if you are setting its value.
« Last Edit: April 03, 2026, 01:52:41 am by msuffidy »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf