This is taken from real world Open Source code. It doesn't matter if you recognise it or not. Everything you need is here. There are no right and wrong answers - it isn't that sort of test. Simply read what follows and answer the questions at the end in as much detail as you can.
There is no time limit. There are no exam conditions. You may find you can answer the questions immediately. You may find yourself revisiting them again and again as things occur to you or as your experience grows. Regardless of the time taken you should be prepared to discuss your answers and latest thoughts in depth during an interview!
Answers should be emailed, along with CV (or resumé) and covering note to jobs@eris-associates.co.uk
A function contains the following fragments of code:
static struct ast_channel *zt_new(struct zt_pvt *i, int state, int startpbx, int index, int law, int transfercapability)
{
struct ast_channel *tmp;
[...]
if (!ast_strlen_zero(i->exten))
ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten));
if (!ast_strlen_zero(i->rdnis))
tmp->cid.cid_rdnis = ast_strdup(i->rdnis);
if (!ast_strlen_zero(i->dnid))
tmp->cid.cid_dnid = ast_strdup(i->dnid);
[...]
The definition of a zt_pvt
structure includes the following relevant members:
static struct zt_pvt {
[...]
char exten[AST_MAX_EXTENSION];
[...]
char rdnis[AST_MAX_EXTENSION];
char dnid[AST_MAX_EXTENSION];
[...]
};
The definitions of ast_strlen_zero
and ast_copy_string
are given in included header files as:
static inline int ast_strlen_zero(const char *s)
{
return (!s || (*s == '\0'));
}
static void ast_copy_string(char *dst, const char *src, size_t size)
{
while (*src && size) {
*dst++ = *src++;
size--;
}
if (!size)
dst--;
*dst = '\0';
}
What is the purpose of the ast_strlen_zero
and
ast_copy_string
definitions?
What issues (if any) might they be trying to avoid?
What issues (if any) might arise from their use?
What might you infer about the skill and mind set of the person that wrote this code?
What issues, or potential issues, are there with this code?
What issues, or potential issues, might you suspect lie elsewhere in the surrounding code?