warning: 'val' may be used uninitialized in this function