Re: [go-nuts] Re: snprintf() in Go with at most constant memory requirement difference than snprintf(3)?

2024-02-06 Thread fgergo
(This time reply to list. Sorry Brian.) On Tue, Feb 6, 2024 at 3:03 PM 'Brian Candler' via golang-nuts wrote: > > > Thanks! In addition to that, It also helps with code with upper limit > > memory-requirement, which fmt.Sprintf() can't. > > If you're processing data from untrusted sources, then

Re: [go-nuts] Re: snprintf() in Go with at most constant memory requirement difference than snprintf(3)?

2024-02-06 Thread 'Brian Candler' via golang-nuts
> Thanks! In addition to that, It also helps with code with upper limit > memory-requirement, which fmt.Sprintf() can't. If you're processing data from untrusted sources, then you probably ought to validate it first. > How to use a limiting > io.Writer with fmt.Sprintf()? How would this limit

Re: [go-nuts] Re: snprintf() in Go with at most constant memory requirement difference than snprintf(3)?

2024-02-06 Thread fgergo
On Tue, Feb 6, 2024 at 12:18 PM 'Brian Candler' via golang-nuts wrote: > > The C functions are mainly there to prevent overrunning already-allocated > buffers, which isn't an issue with Go. Thanks! In addition to that, It also helps with code with upper limit memory-requirement, which

[go-nuts] Re: snprintf() in Go with at most constant memory requirement difference than snprintf(3)?

2024-02-06 Thread 'Brian Candler' via golang-nuts
The C functions are mainly there to prevent overrunning already-allocated buffers, which isn't an issue with Go. You could truncate the response: a := fmt.Sprintf("%s", "Blah blah blah")[0:10] You could use suitable precision specifiers: a := fmt.Sprintf("%.10s", "Blah blah blah")