[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] kern: fix mig_strncpy
From: |
Samuel Thibault |
Subject: |
Re: [PATCH] kern: fix mig_strncpy |
Date: |
Mon, 24 Feb 2014 23:06:43 -0500 |
User-agent: |
Mutt/1.5.21+34 (58baf7c9f32f) (2010-12-30) |
Justus Winter, le Sat 22 Feb 2014 11:25:14 +0100, a écrit :
> Previously, the function mig_strncpy would always zero-terminate the
> destination string. Make mig_strncpy behave like mig_strncpy and
> strncpy in the glibc. Also fix the implementation of mig_strncpy to
> return the length of the written string to align the implementation
> with the declaration in include/mach/mig_support.h.
>
> * kern/ipc_mig.c (mig_strncpy): Do not zero-terminate the destination
> string. Return length of destination string.
Ack.
> ---
> kern/ipc_mig.c | 36 ++++++++++++++++++++----------------
> 1 file changed, 20 insertions(+), 16 deletions(-)
>
> diff --git a/kern/ipc_mig.c b/kern/ipc_mig.c
> index bbc38cf..f2c3f45 100644
> --- a/kern/ipc_mig.c
> +++ b/kern/ipc_mig.c
> @@ -272,10 +272,10 @@ mig_put_reply_port(
> /*
> * mig_strncpy.c - by Joshua Block
> *
> - * mig_strncp -- Bounded string copy. Does what the library routine strncpy
> - * OUGHT to do: Copies the (null terminated) string in src into dest, a
> - * buffer of length len. Assures that the copy is still null terminated
> - * and doesn't overflow the buffer, truncating the copy if necessary.
> + * mig_strncpy -- Bounded string copy. Does what the library routine
> + * strncpy does: Copies the (null terminated) string in src into dest,
> + * a buffer of length len. Returns the length of the destination
> + * string excluding the terminating null.
> *
> * Parameters:
> *
> @@ -285,22 +285,26 @@ mig_put_reply_port(
> *
> * len - Length of destination buffer.
> */
> -void mig_strncpy(dest, src, len)
> -char *dest;
> -const char *src;
> -int len;
> +vm_size_t
> +mig_strncpy(dest, src, len)
> + char *dest;
> + const char *src;
> + int len;
> {
> - int i;
> + char *dest_ = dest;
> + int i;
>
> - if (len <= 0)
> - return;
> + if (len <= 0)
> + return 0;
>
> - for (i=1; i<len; i++)
> - if (! (*dest++ = *src++))
> - return;
> + for (i = 0; i < len; i++) {
> + if (! (*dest = *src))
> + break;
> + dest++;
> + src++;
> + }
>
> - *dest = '\0';
> - return;
> + return dest - dest_;
> }
>
> #define fast_send_right_lookup(name, port, abort)
> \
> --
> 1.8.5.2
>
--
Samuel
> Subject: pb fvwm95-2 comment l'installer le compiler???
> Merci d'avance
je te conseille d'être un peu plus précis dans l'exposé de ton pb...
-+- EJ in guide du linuxien pervers :"Les modéros sont sympas !" -+-