_putstr

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

_putstr

1,138 Views
adyr
Contributor V

Hi,

Is the _putstr function in print_prv.c correct?

I'm using KSDK 1.3 + MQX and I am calling:

numChars = sprintf ("%s%s%.19s", data1, data2, data3 );

where data3 is a string containing 48 characters. The value returned is the length of the 3 source strings even though it has only inserted 19 of the 48 characters from data3.

When I look at _putstr it seems to set compare = true after inserting the required number of characters so the count continues to increase.

Should this not set continue = false to abort the loop so the returned count is the number of characters actually inserted?

Also the comments for _putstr state the default value for max_count is 0 (unlimited size), but this would results in no characters being output. Is it the comment or the code that is wrong?

Best regards,

Adrian.

0 Kudos
Reply
3 Replies

843 Views
soledad
NXP Employee
NXP Employee

Hi,

Could you please share the code and let me know the device you are using, in order to reproduce this issue?

Regards

Soledad

0 Kudos
Reply

843 Views
adyr
Contributor V

I am using the K66 and a simple example of the problem would be:

char buf[ 30 ];
char* txt1 = "Some really long text obtained from somewhere but I only have space for a small amount";
uint32_t numChars = sprintf( buf, "Output: %.18s...", txt1 );
UART_DRV_SendDataBlocking( uartCom4_IDX, (uint8_t*)buf, numChars, 10 );

According to sprintf it should return the number of characters generated so the above should return 29. But it actually returns 97 (I think, but I've not run it) as it takes the full length of txt1 instead of the 18 characters it actually copied to the buffer.

I know in the example I could just use strlen( buf ) but my real code is doing a lot more than the example and it is filling a buffer from multiple sources so it is critical that the number of characters placed in the buffer is accurate.

Regards,

Adrian.

0 Kudos
Reply

843 Views
DavidS
NXP Employee
NXP Employee

Hi Adrian,

Please try following:

    uint32_t numChars = sprintf( buf, "Output: %-18.18s...", txt1 );

Regards,

David

0 Kudos
Reply