static int ki_handle_event(glw_keyintercept_t *ki, event_t *e) { if(event_is_action(e, ACTION_BS)) { if(ki->buflen == 0) return 0; ki->buflen--; updatestr(ki); return 1; } if(event_is_type(e, EVENT_UNICODE)) { event_int_t *ei = (event_int_t *)e; int c = ei->val; if(c == 32 && ki->buflen == 0) return 0; // space as first char is not something we trig on if(ki->buflen == KI_BUF_LEN - 1) return 1; ki->buf[ki->buflen] = c; ki->buflen++; updatestr(ki); return 1; } return 0; }
// simple std::string usage to see if valgrind reports memory leak // int main(int argc, char** argv) { std::string str("foo"); str = "bar"; str = "this is bar"; Foo *foo = new Foo(str); foo->m_str = "this is foo"; delete foo; Foo *f2 = new Foo(); f2->m_str = "this is f2"; updatestr(f2->m_str); f2->m_str = "this is another f2"; delete f2; // if you exit then there is report in leak in the std::string //exit(1); // std::string nullstr; printf("nullstr.c_str() = %p\n", nullstr.c_str()); char *nullcstr = NULL; nullstr.assign(nullcstr); }