On Tue, 15 Dec 2009, Arjen de Korte wrote:

> Citeren Kjell Claesson <[email protected]>:
> 
> > > Although gcc can handle it, it's not portable C code.
> > > 
> > > What size should the answer array be?
> > > 
> > 
> > It depends on the ups.
> 
> If the size of the answer isn't known at compile time, you should either
> allocate it dynamically with malloc() or calloc() (at runtime) or hardcode the
> size so big that any reply should fit in it.

This may be the least intrusive way to fix it.
------------------------------
--- nut-svn/drivers/bcmxcp.c.old        2009-12-15 09:32:45.000000000 -0800
+++ nut-svn/drivers/bcmxcp.c    2009-12-15 14:03:34.602495008 -0800
@@ -871,13 +871,14 @@
 
 int init_outlet(unsigned char len)
 {
-       unsigned char answer[len];
+       unsigned char *answer;
        int iIndex = 0, res, num;
        int num_outlet, size_outlet;
        int outlet_num, outlet_state;
        short auto_dly_off, auto_dly_on;
        char outlet_name[25];
 
+       answer = xmalloc((size_t) len);
        res = command_read_sequence(PW_OUT_MON_BLOCK_REQ, answer);
        if (res <= 0)
                fatal_with_errno(EXIT_FAILURE, "Could not communicate with the 
ups");
------------------------------

-- 
Tim Rice                                Multitalents    (707) 887-1469
[email protected]



_______________________________________________
Nut-upsdev mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/nut-upsdev

Reply via email to