On 28 January 2015 at 14:27, Savolainen, Petri (NSN - FI/Espoo) <petri.savolai...@nsn.com> wrote: > There's no warnings as long as size_t and ssize_t variables are not compared. And there is no need to compare size_t and ssize_t variables or values. Problem solved.
> > > len = -odp_cpumask_to_str(&mask, NULL, 0); > > This looks odd with the minus sign... Almost len -= ... To me it looks like we are negating the value of odp_cpumask_to_str(). But you could also write it like this: len = (-odp_cpumask_to_str(&mask, NULL, 0)); > > > ssize_t odp_cpumask_to_str(const odp_cpumask_t *mask, char *buf, ssize_t > bufsz); > > This forces application to use signed buf length and implementation to check > that bufsz >0. It works with size_t bufsz as well. I actually already changed that. > > > size_t odp_cpumask_to_str(const odp_cpumask_t *mask, char *str, size_t len) > would be closer to snprintf() types and logic... which people already know. I am not sure many programmers know the complete snprintf return values that well. It is easier to assume that your buffer will be large enough (because you (think you) know your inputs) and then just ignore the returned value. To me it is quesy that some positive values indicates success and other positive values indicate failure. Especially since we now have a convention of using negative values to signify error and there are also more than one instance of using non-zero positive values for success. > > > -Petri > > >> -----Original Message----- >> From: ext Ola Liljedahl [mailto:ola.liljed...@linaro.org] >> Sent: Wednesday, January 28, 2015 2:47 PM >> To: Savolainen, Petri (NSN - FI/Espoo) >> Cc: LNG ODP Mailman List >> Subject: Re: [lng-odp] odp_cpumask.h >> >> The following code compiles without warnings or errors: >> #include <assert.h> >> #include <stddef.h> >> #include <stdio.h> >> #include <stdlib.h> >> #include <sys/types.h> >> #include <odp_cpumask.h> >> >> void test(odp_cpumask_t mask) >> { >> /* Start with a small value so that a retry will be forced */ >> size_t len = 1; >> char *str; >> >> for (;;) { >> ssize_t out; >> str = malloc(len); >> if (str == NULL) >> perror("malloc"), exit(EXIT_FAILURE); >> >> out = odp_cpumask_to_str(&mask, str, len); >> if (out > 0) /* success */ >> break; >> >> /* failure, try with the recommended buffer size */ >> free(str); >> len = -out; >> } >> /* do something with str */ >> free(str); >> } >> >> void test2(odp_cpumask_t mask) >> { >> char *str; >> size_t len; >> ssize_t out; >> /* Call with zero-length buffer, this will fail and return >> required >> * buffer size */ >> len = -odp_cpumask_to_str(&mask, NULL, 0); >> str = malloc(len); >> if (str == NULL) >> perror("malloc"), exit(EXIT_FAILURE); >> out = odp_cpumask_to_str(&mask, str, len); >> assert(out > 0); >> /* do something with str */ >> free(str); >> } >> >> ssize_t odp_cpumask_to_str(const odp_cpumask_t *mask, char *buf, ssize_t >> bufsz); >> >> gcc -c -std=c99 -W -Wall -ansi -pedantic test.c -I >> platform/linux-generic/include/api/ >> >> Am I missing any important compiler flags this time? >> >> >> On 28 January 2015 at 13:32, Savolainen, Petri (NSN - FI/Espoo) >> <petri.savolai...@nsn.com> wrote: >> >> (maybe your audio was breaking on call yesterday on that part). >> >> I have tested mixing size_t and ssize_t and neither gcc nor clang >> >> complained. I was using -Wall -ansi -pedantic. >> > >> > Missing -W from there ? -Wall is not enough... >> > >> > _______________________________________________ lng-odp mailing list lng-odp@lists.linaro.org http://lists.linaro.org/mailman/listinfo/lng-odp