Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation or warning that Syslog constructor doesn't make deep copies #17

Open
hydrogen18 opened this issue Sep 9, 2018 · 1 comment
Assignees

Comments

@hydrogen18
Copy link

I just spent 1 or 2 hours trying to debug why this simple usage case does not work at all


Syslog *mySyslog;
WiFiUDP myUdp;
void start_syslog(void){
char hostname[64];
read_hostname_from_config(&hostname); // read NULL terminated string from EEPROM, SD-card, etc.
mySyslog = new Syslog(
        myUdp
        hostname,
        2222, 
        "myhostname",
        "appName"
        LOG_LOCAL3, 
        SYSLOG_PROTO_IETF);
}

Basically this code would run but when I try and use mySyslog->log I get false as a return value. I spent a while troubleshooting my code before I looked at your implementation of Syslog.cpp. It was pretty obvious that my problem was the constructor just stores the pointer, not copies it. If you read the configuration from some dynamic source it means you can't pass in a stack variable.

I switched to using a global array for my hostname and it worked fine.

I think this implementation is fine, but it might save others some headache if you added notes warning them the constructor does not make deep copies and the caller must keep the memory segment around and unaltered.

@devbar
Copy link

devbar commented Feb 19, 2023

Great idea! I ran into same issue, thanks for comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants