>
> Memory may be allocated with malloc but unless function
> emcCommandBuffer->write(...) store the pointer internally, copy data
> internally is below might be a much better idea. If state_msg variable is
> not used further down or at least is not supposed the block will also limit
> life time of variable.
>

this row of code is extract from shcom.cc:

int emcCommandSend(RCS_CMD_MSG & cmd)
{
    // write command
    if (emcCommandBuffer->write(&cmd)) {
        return -1;
    }
    emcCommandSerialNumber = cmd.serial_number;
    return 0;
}

int sendEstop()
{
    EMC_TASK_SET_STATE state_msg;

    state_msg.state = EMC_TASK_STATE_ESTOP;
    emcCommandSend(state_msg);
    if (emcWaitType == EMC_WAIT_RECEIVED) {
return emcCommandWaitReceived();
    } else if (emcWaitType == EMC_WAIT_DONE) {
return emcCommandWaitDone();
    }

    return 0;
}

but there is not malloc for state_msg and not see where is initialized ....

In my row code is the same situation .... but if try to use malloc obtain
warning like "no viable conversion from int to EMC_TASK_SET_STATE" .... is
because I try to use malloc with bad variable type?
In my QtDro.h file I use these .hh file of Lcnc:

#include "include/cmd_msg.hh"
#include "include/stat_msg.hh"
#include "include/emc_nml.hh"
#include <stat_msg.hh>
#include <cmd_msg.hh>
#include <nml.hh>
#include "emc.hh"               // EMC NML
#include "include/emcglb.h"             // EMC_NMLFILE, TRAJ_MAX_VELOCITY,
TOOL_TABLE_FILE
#include "include/emccfg.h"             // DEFAULT_TRAJ_MAX_VELOCITY
#include "inifile.hh"           // INIFILE

Not understand how to initialize state_msg.

thanks and good end of 2019 and new 2020 at all.

bkt

Il giorno gio 19 dic 2019 alle ore 17:54 N <nicklas.karlsso...@gmail.com>
ha scritto:

> > just a guess.
> >
> > EMC_TASK_SET_STATE *state_msg;
> >
> > state_msg is a pointer, yet no memory allocated for it.
> >
> > state_msg->state = EMC_TASK_STATE_OFF;
> >
> > you try to write in a memory space that officially has no memory
> assigned yet.
> >
> > ju
> You are correct no memory assigned. Maybe no warning for using an
> unitialized variable, if turned a warning would be issued for using
> unitizialized variable.
>
> Memory may be allocated with malloc but unless function
> emcCommandBuffer->write(...) store the pointer internally, copy data
> internally is below might be a much better idea. If state_msg variable is
> not used further down or at least is not supposed the block will also limit
> life time of variable.
>
> {
>   EMC_TASK_SET_STATE state_msg;
>
>   state_msg.state = EMC_TASK_STATE_OFF;
>   state_msg.serial_number = ++emcCommandSerialNumber;
>   emcCommandBuffer->write(&state_msg);
> }
>
>
> _______________________________________________
> Emc-developers mailing list
> Emc-developers@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/emc-developers
>

_______________________________________________
Emc-developers mailing list
Emc-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to