tests: some fixes

This commit is contained in:
Khaïs COLIN 2025-03-19 17:58:46 +01:00 committed by Jérôme Guélen
parent ea3ecaaf31
commit f0755cd6c4
No known key found for this signature in database
3 changed files with 29 additions and 13 deletions

19
src/env/env_manip.c vendored
View file

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* env_manip.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/12 18:29:12 by jguelen #+# #+# */
/* Updated: 2025/03/14 10:52:39 by jguelen ### ########.fr */
/* Created: 2025/03/19 17:55/24 by khais #+# #+# */
/* Updated: 2025/03/19 17:55:24 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -97,8 +97,8 @@ static void env_add_back(t_env **env, t_env *new)
** freed. In case a node matching the given key is found the provided key value
** is freed.
**
** If key is null, both key and value are freed and NULL is returned. ft_errno
** is set to FT_EINVAL. We therefore allow for a value to be NULL.
** If key or value is null, both key and value are freed and NULL is returned.
** ft_errno is set to FT_EINVAL. We therefore allow for a value to be NULL.
**
** If key is an empty string, key and value are freed, ft_errno is set to
** FT_EBADID, and NULL is returned.
@ -111,12 +111,19 @@ static void env_add_back(t_env **env, t_env *new)
** Warning: does not check for validity of a key beyond what is described above.
**
** Implementation notes: free2 always returns NULL
**
** Note: once you pass a key to this function, if you pass it a second time, it
** will cause bad behaviour.
**
** Once you passed key and/or value to this function, env is the owner of these
** values and is responsible for freeing them. Do not pass multiple times the
** same pointers to this function!
*/
t_env *env_set_entry(t_env **env, char *key, char *value)
{
t_env *node;
if (key == NULL)
if (key == NULL || value == NULL)
return (ft_errno(FT_EINVAL), free2(key, value));
if (*key == '\0')
return (ft_errno(FT_EBADID), free2(key, value));

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* variable_subst.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/06 12:48:00 by khais #+# #+# */
/* Updated: 2025/03/14 09:56:51 by jguelen ### ########.fr */
/* Created: 2025/03/19 17:28/29 by khais #+# #+# */
/* Updated: 2025/03/19 17:28:29 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -136,6 +136,7 @@ t_worddesc *word_var_expansion(t_worddesc *word, t_minishell *app)
i = 0;
while (word->word[i] && word->word[i + 1])
{
rep_len = 1;
if (word->marker[i] != '\'' && word->word[i] == '$')
{
rep = calculate_replacement(word, app, i, &id_len);