vsnprintf()

Linux specific forum
infratec
Always Here
Always Here
Posts: 7616
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

vsnprintf()

Post by infratec »

I try to use libvlc.pbi and vlc.pbi in Linux.
https://www.purebasic.fr/english/viewtopic.php?t=77848

For that I added in vlc.pbi

Code: Select all

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Windows
    CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
      Macro snprintf_name : "__vsnprintf" : EndMacro  
    CompilerElse
      Macro snprintf_name : "_vsnprintf" : EndMacro
    CompilerEndIf  
  CompilerCase #PB_OS_Linux
    Macro snprintf_name : "vsnprintf" : EndMacro
  CompilerCase #PB_OS_MacOS
CompilerEndSelect

ImportC ""
  snprintf(*str.p-utf8, size.l, *format.p-utf8, ap.i) As snprintf_name
EndImport
This works in general. The application is starting, but results in memory errror.
Same like here:
https://www.purebasic.fr/english/viewtopic.php?p=392883

It is used in a vlc logging callback (vlc_eventdebug which calls vlc_stringformat)

Code: Select all

Procedure.s vlc_stringformat(*fmt, args)
	Protected sret.s
	Protected c.i
	c = snprintf(#Null, 0, *fmt, args)
	If c
		Protected *pm = AllocateMemory(c)
		If *pm
			snprintf(*pm, c, *fmt, args)
			sret = vlc_safePeekS(*pm, c)
			FreeMemory(*pm)
		EndIf
	EndIf
	ProcedureReturn sret
EndProcedure

ProcedureC vlc_eventdebug (*vlc.vlc, level.i, *ctx, *fmt, args)
	Select level
		Case #LIBVLC_DEBUG
			Debug "#LIBVLC_DEBUG : " + vlc_stringformat(*fmt, args)
		Case #LIBVLC_NOTICE
			Debug "#LIBVLC_NOTICE	: " + vlc_stringformat(*fmt, args)
		Case #LIBVLC_WARNING
			Debug "#LIBVLC_WARNING : " + vlc_stringformat(*fmt, args)
		Case #LIBVLC_ERROR
			Debug "#LIBVLC_ERROR : " + vlc_stringformat(*fmt, args)
	EndSelect
EndProcedure
The problem is the va_list args.
In Windows it works.
In linux it looks that the args pointer points to a wrong address.

Any idea?
infratec
Always Here
Always Here
Posts: 7616
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: vsnprintf()

Post by infratec »

Strange thing is that the first call to get the needed bytes works correct.
I get the same 34 bytes as in windows.
But the second call insert a mess in the string and returns only 23 bytes.
Post Reply