# vsprintf returns int not char*

- Thread: https://externals.io/message/14272
- Original archive: https://news-web.php.net/php.internals/14272
- Started by Kamesh Jayachandran on 2005-01-04T08:07:04+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #14272 — Kamesh Jayachandran — 2005-01-04T08:07:04+00:00

URL: https://externals.io/message/14272#14272

Hi Derick,
in php-src/main/php_sprintf.c
PHPAPI int
php_sprintf (char*s, const char* format, ...)
{
  va_list args;
  char *ret; //ret should be of type integer as vsprintf returns int
  rather than char*

  va_start (args, format);
  s[0] = '\0';
  ret = vsprintf (s, format, args);
  va_end (args);
  if (!ret) //This check should be if(ret < 0) as ret will have the
  number of characters printed to s  
//If an output error is encountered, a negative  value  is returned.
    return -1;
  return strlen (s);
}
ret should be of type integer as vsprintf returns int rather than char*.
if (!ret) should be if(ret < 0)


With regards
Kamesh Jayachandran

---

## #14275 — Derick Rethans — 2005-01-04T13:44:56+00:00

URL: https://externals.io/message/14272#14275 · In reply to: #14272

> Hi Derick,
> in php-src/main/php_sprintf.c
> PHPAPI int
> php_sprintf (char*s, const char* format, ...)
> {
>   va_list args;
>   char *ret; //ret should be of type integer as vsprintf returns int rather than char*

It is already an int, please update your source trees.

Derick

-- 
Derick Rethans
http://derickrethans.nl | http://ez.no | http://xdebug.org

---

## #14284 — Kamesh Jayachandran — 2005-01-05T06:43:06+00:00

URL: https://externals.io/message/14272#14284 · In reply to: #14275

Hi Derick,
Sorry I have seen this PHP-5.0.3 bundle. The change is there on December
17 commit on PHP5_0.
Still I feel this should be replaced
 if (!ret)
    return -1;

by 
 if (ret<0)
    return -1;

As the document for vsprintf states as follows,
 If  an  output  error  is encountered, a negative value is
       returned.

With regards
Kamesh Jayachandran

On Tue, 4 Jan 2005 14:44:56 +0100 (CET), "Derick Rethans"
<derick@php.net> said:
> 
> 
> > […]
> 
> It is already an int, please update your source trees.
> 
> Derick
> 
> -- 
> Derick Rethans
> http://derickrethans.nl | http://ez.no | http://xdebug.org
