mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] newlocale: set errno on failure
@ 2016-07-25  9:35 Julien Ramseier
  2016-07-25  9:46 ` Alexander Monakov
  0 siblings, 1 reply; 3+ messages in thread
From: Julien Ramseier @ 2016-07-25  9:35 UTC (permalink / raw)
  To: musl

As per POSIX, newlocale() should set errno when it fails.

---
 src/locale/newlocale.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/locale/newlocale.c b/src/locale/newlocale.c
index f50bbe9..2bfb832 100644
--- a/src/locale/newlocale.c
+++ b/src/locale/newlocale.c
@@ -1,3 +1,4 @@
+#include <errno.h>
 #include <stdlib.h>
 #include <string.h>
 #include "locale_impl.h"
@@ -42,6 +43,7 @@ locale_t __newlocale(int mask, const char *name, locale_t loc)
 		return UTF8_LOCALE;

 	if ((loc = malloc(sizeof *loc))) *loc = tmp;
+	else errno = ENOMEM;

 	return loc;
 }
--
2.9.2



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] newlocale: set errno on failure
  2016-07-25  9:35 [PATCH] newlocale: set errno on failure Julien Ramseier
@ 2016-07-25  9:46 ` Alexander Monakov
  2016-07-25  9:48   ` Julien Ramseier
  0 siblings, 1 reply; 3+ messages in thread
From: Alexander Monakov @ 2016-07-25  9:46 UTC (permalink / raw)
  To: musl

On Mon, 25 Jul 2016, Julien Ramseier wrote:
> As per POSIX, newlocale() should set errno when it fails.
> 
> ---
>  src/locale/newlocale.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/src/locale/newlocale.c b/src/locale/newlocale.c
> index f50bbe9..2bfb832 100644
> --- a/src/locale/newlocale.c
> +++ b/src/locale/newlocale.c
> @@ -1,3 +1,4 @@
> +#include <errno.h>
>  #include <stdlib.h>
>  #include <string.h>
>  #include "locale_impl.h"
> @@ -42,6 +43,7 @@ locale_t __newlocale(int mask, const char *name, locale_t loc)
>  		return UTF8_LOCALE;
> 
>  	if ((loc = malloc(sizeof *loc))) *loc = tmp;
> +	else errno = ENOMEM;

When malloc returns NULL, it will set errno to ENOMEM; there's no need for
callers to handle that separately.

Did you hit some issue in practice that prompted this change?

Alexander


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] newlocale: set errno on failure
  2016-07-25  9:46 ` Alexander Monakov
@ 2016-07-25  9:48   ` Julien Ramseier
  0 siblings, 0 replies; 3+ messages in thread
From: Julien Ramseier @ 2016-07-25  9:48 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 1027 bytes --]

Oops I did miss that.
Sorry for the noise.

- Julien

> Le 25 juil. 2016 à 11:46, Alexander Monakov <amonakov@ispras.ru> a écrit :
> 
> On Mon, 25 Jul 2016, Julien Ramseier wrote:
>> As per POSIX, newlocale() should set errno when it fails.
>> 
>> ---
>> src/locale/newlocale.c | 2 ++
>> 1 file changed, 2 insertions(+)
>> 
>> diff --git a/src/locale/newlocale.c b/src/locale/newlocale.c
>> index f50bbe9..2bfb832 100644
>> --- a/src/locale/newlocale.c
>> +++ b/src/locale/newlocale.c
>> @@ -1,3 +1,4 @@
>> +#include <errno.h>
>> #include <stdlib.h>
>> #include <string.h>
>> #include "locale_impl.h"
>> @@ -42,6 +43,7 @@ locale_t __newlocale(int mask, const char *name, locale_t loc)
>> 		return UTF8_LOCALE;
>> 
>> 	if ((loc = malloc(sizeof *loc))) *loc = tmp;
>> +	else errno = ENOMEM;
> 
> When malloc returns NULL, it will set errno to ENOMEM; there's no need for
> callers to handle that separately.
> 
> Did you hit some issue in practice that prompted this change?
> 
> Alexander


[-- Attachment #2: Type: text/html, Size: 6220 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-07-25  9:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-25  9:35 [PATCH] newlocale: set errno on failure Julien Ramseier
2016-07-25  9:46 ` Alexander Monakov
2016-07-25  9:48   ` Julien Ramseier

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).