anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: godotengine/godot-cpp
Issue: Passing nullptr to functions with nullable parameter (`*parent = nullptr`) crashes

For this kind of interface:

```cpp
TreeItem *create_item(TreeItem *parent = nullptr, int32_t idx = -1);
```

Current `binding_generator.py` generates implementation like below:

```cpp
TreeItem *Tree::create_item(TreeItem *parent, int32_t idx) {
    /* ... snip ... */
    return internal::_call_native_mb_ret_obj<TreeItem>(___method_bind, _owner, parent->_owner, &idx_encoded);
}
```

When you actually call this function with the default argument, it crashes at `parent->_owner` because `parent` is `nullptr`.
If I change `parent->_owner` to `parent ? parent->_owner : nullptr`, then it is working.

I noticed this bug when I was using `TreeItem`, but I think this issue also affects other classes with similar interfaces too. I assume the script should generate different code for nullable parameters. 

EDIT: Theoretically, there might be some other cases where the function has a nullable pointer parameter without default value, but I'm not sure how many of godot-cpp's API matches that form.

Relevant location:
https://github.com/godotengine/godot-cpp/blob/bffedfed1eb297b697fa4d139ac9d03b5c9fabd6/binding_generator.py#L1499-L1501



Changed files:
binding_generator.py

diff --git a/binding_generator.py b/binding_generator.py
index c1e2a69..6294fd5 100644
--- a/binding_generator.py
+++ b/binding_generator.py
@@ -1587,7 +1587,9 @@ def get_encoded_arg(arg_name, type_name, type_meta):
         result.append(f"\\tPtrToArg<{correct_type(type_name)}>::encode({name}, &{name}_encoded);")
         name = f"&{name}_encoded"
     elif is_engine_class(type_name):
-        name = f"{name}->_owner"
+        # `{name}` is a C++ wrapper, it contains a field which is the object's pointer Godot expects.
+        # We have to check `nullptr` because when the caller sends `nullptr`, the wrapper itself will be null.
+        name = f"({name} != nullptr ? {name}->_owner : nullptr)"
     else:
         name = f"&{name}"
Repository: godotengine/godot-cpp
Issue: Release builds are linking with debug libraries

Since updating for Godot 4 beta 4 support, users have been reporting an issue where my builds produced using `template_release` are linked with debug runtime libraries: https://github.com/codecat/godot-tbloader/issues/36

This might be related to #867, but I don't really know enough about SCons to properly debug this. I believe my SCons file is properly configured though, so this might be a bug in godot-cpp?

Changed files:
tools/windows.py, tools/targets.py

diff --git a/tools/targets.py b/tools/targets.py
index b3d1c52..e9857dd 100644
--- a/tools/targets.py
+++ b/tools/targets.py
@@ -55,7 +55,7 @@ def generate(env):
     env["optimize"] = ARGUMENTS.get("optimize", opt_level)
     env["debug_symbols"] = get_cmdline_bool("debug_symbols", env.dev_build)
 
-    if "is_msvc" in env and env["is_msvc"]:
+    if env.get("is_msvc", False):
         if env["debug_symbols"]:
             env.Append(CCFLAGS=["/Zi", "/FS"])
             env.Append(LINKFLAGS=["/DEBUG:FULL"])
@@ -66,8 +66,12 @@ def generate(env):
         elif env["optimize"] == "size":
             env.Append(CCFLAGS=["/O1"])
             env.Append(LINKFLAGS=["/OPT:REF"])
-        elif env["optimize"] == "debug" or env["optimize"] == "none":
-            env.Append(CCFLAGS=["/Od"])
+
+        if env["optimize"] == "debug" or env["optimize"] == "none":
+            env.Append(CCFLAGS=["/MDd", "/Od"])
+        else:
+            env.Append(CCFLAGS=["/MD"])
+
     else:
         if env["debug_symbols"]:
             if env.dev_build:
diff --git a/tools/windows.py b/tools/windows.py
index 2983f50..16acc28 100644
--- a/tools/windows.py
+++ b/tools/windows.py
@@ -27,10 +27,6 @@ def generate(env):
         env.Append(CPPDEFINES=["TYPED_METHOD_BIND", "NOMINMAX"])
         env.Append(CCFLAGS=["/EHsc"])
         env.Append(LINKFLAGS=["/WX"])
-        if env["debug_symbols"] or env["target"] == "debug":
-            env.Append(CCFLAGS=["/MDd"])
-        else:
-            env.Append(CCFLAGS=["/MD"])
 
         if env["use_clang_cl"]:
             env["CC"] = "clang-cl"
Repository: psd-tools/psd-tools
Issue: composite() error on ex-vector layer

**Description:**

It seems like psd_tools expects a layer with a `stroke` to always have a `vector_mask`.
Photoshop 21.2.6 gives me a psd (attached) with only a stroke (it was a vector layer converted to pixels).
Because of that, I have the following error when I try to `composite()` the layer:
```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "\\Python\\Python38\\lib\\site-packages\\psd_tools\\api\\layers.py", line 418, in composite
    return composite_pil(self, color, alpha, viewport, layer_filter, force)
  File "\\Python\\Python38\\lib\\site-packages\\psd_tools\\composite\\__init__.py", line 32, in composite_pil
    color, _, alpha = composite(
  File "\\Python\\Python38\\lib\\site-packages\\psd_tools\\composite\\__init__.py", line 102, in composite
    compositor.apply(layer)
  File "\\Python\\Python38\\lib\\site-packages\\psd_tools\\composite\\__init__.py", line 196, in apply
    color, shape, alpha = self._get_object(layer)
  File "\\Python\\Python38\\lib\\site-packages\\psd_tools\\composite\\__init__.py", line 338, in _get_object
    color_s, shape_s, alpha_s = self._get_stroke(layer)
  File "\\Python\\Python38\\lib\\site-packages\\psd_tools\\composite\\__init__.py", line 418, in _get_stroke
    shape = draw_stroke(layer)
  File "\\Python\\Python38\\lib\\site-packages\\psd_tools\\composite\\vector.py", line 42, in draw_stroke
    return _draw_path(
  File "\\Python\\Python38\\lib\\site-packages\\psd_tools\\composite\\vector.py", line 64, in _draw_path
    for subpath in layer.vector_mask.paths:
AttributeError: 'NoneType' object has no attribute 'paths'
```

**To Reproduce:**
```python
from psd_tools import PSDImage
PSDImage.open('Forme_783.psd')[0].composite()
```

**File and screenshots**
[Forme_783.zip](https://github.com/psd-tools/psd-tools/files/8341524/Forme_783.zip)


**Environment**
 - Python 3.7 and 3.8
 - psd_tools 1.9.18


Changed files:
src/psd_tools/composite/__init__.py

diff --git a/src/psd_tools/composite/__init__.py b/src/psd_tools/composite/__init__.py
index b536f5d..f200aef 100644
--- a/src/psd_tools/composite/__init__.py
+++ b/src/psd_tools/composite/__init__.py
@@ -334,7 +334,7 @@ class Compositor(object):
             color = self._apply_clip_layers(layer, color, alpha)
 
         # Apply stroke if any.
-        if layer.has_stroke() and layer.stroke.enabled:
+        if layer.has_vector_mask() and layer.has_stroke() and layer.stroke.enabled:
             color_s, shape_s, alpha_s = self._get_stroke(layer)
             compositor = Compositor(self._viewport, color, alpha)
             compositor._apply_source(
Repository: psd-tools/psd-tools
Issue: Assetion Error opening a valid PSD 

**Description**
Opening the attached PSD file with psd-tools, it raises an AssetionError.
Opening the same file with Photoshop it seems everything is ok.

**File to test**
[error.psd.zip](https://github.com/psd-tools/psd-tools/files/8728341/error.psd.zip)

**Version**
psd-tools: 1.9.20
Python: 3.8.12



Changed files:
src/psd_tools/psd/layer_and_mask.py

diff --git a/src/psd_tools/psd/layer_and_mask.py b/src/psd_tools/psd/layer_and_mask.py
index e9cedbe..170408e 100644
--- a/src/psd_tools/psd/layer_and_mask.py
+++ b/src/psd_tools/psd/layer_and_mask.py
@@ -56,7 +56,10 @@ class LayerAndMaskInformation(BaseElement):
             self = cls()
         else:
             self = cls._read_body(fp, end_pos, encoding, version)
-        assert fp.tell() <= end_pos
+        if fp.tell() > end_pos:
+            logger.warning(
+                'LayerAndMaskInformation is broken: current fp=%d, expected=%d' % (
+                    fp.tell(), end_pos))
         fp.seek(end_pos, 0)
         return self
Repository: psd-tools/psd-tools
Issue: Vivid Light not rendered correctly

Please see attached PSD.  Vivid light mode is not rendered correctly in psd_tools.  I am using the "new" composite, but I think the old one also has a (different) problem.

[psdtools_bug_vividlight.zip](https://github.com/psd-tools/psd-tools/files/4783044/psdtools_bug_vividlight.zip)


Changed files:
src/psd_tools/composite/blend.py, tests/psd_tools/composite/test_blend.py

diff --git a/src/psd_tools/composite/blend.py b/src/psd_tools/composite/blend.py
index 009534b..ae8ca4b 100644
--- a/src/psd_tools/composite/blend.py
+++ b/src/psd_tools/composite/blend.py
@@ -92,15 +92,12 @@ def vivid_light(Cb, Cs):
     the contrast.
     """
 
-    # index = Cs > 0.5
-    # B = color_dodge(Cb, Cs)
-    # B[index] = color_burn(Cb, Cs)[index]
-    # return B
-
-    # On contrary to what the document says, Photoshop generates the inverse of
-    # hard_mix
-    return hard_mix(Cs, Cb)
-
+    Cs2 = Cs * 2
+    index = Cs > 0.5
+    B = color_burn(Cb, Cs2)
+    D = color_dodge(Cb, Cs2 - 1)
+    B[index] = D[index]
+    return B
 
 def linear_light(Cb, Cs):
     """
@@ -293,7 +290,7 @@ def _set_sat(C, s):
     index_min = (C == C_min)
 
     index = index_mid & index_diff
-    B[index] = C_mid[index] - C_min[index] * \\
+    B[index] = (C_mid[index] - C_min[index]) * \\
         s[index] / (C_max[index] - C_min[index] + 1e-9)
     index = index_max & index_diff
     B[index] = s[index]
diff --git a/tests/psd_tools/composite/test_blend.py b/tests/psd_tools/composite/test_blend.py
index d2046a6..34a8b6e 100644
--- a/tests/psd_tools/composite/test_blend.py
+++ b/tests/psd_tools/composite/test_blend.py
@@ -19,7 +19,7 @@ logger = logging.getLogger(__name__)
     ('blend-modes/linear-burn.psd', ),
     ('blend-modes/hard-light.psd', ),
     ('blend-modes/soft-light.psd', ),
-    ('blend-modes/vivid-light.psd', ),
+    pytest.param('blend-modes/vivid-light.psd', marks=pytest.mark.xfail(reason="vivid light algorithm discrepency")),
     ('blend-modes/linear-light.psd', ),
     ('blend-modes/pin-light.psd', ),
     ('blend-modes/difference.psd', ),
Repository: psd-tools/psd-tools
Issue: Runtime warning for certain blending

**Describe the bug**

Blending seems to fail when a certain condition meets.

```
 /usr/local/lib64/python3.7/site-packages/psd_tools/composite/blend.py:265: RuntimeWarning: invalid value encountered in true_divide
  C[index] = L_i + (C[index] - L_i) * L_i / (L_i - C_min[index])
```

**To Reproduce**

Call `composite` for certain PSD files having invalid pixel values.

**Expected behavior**

Blending should workaround ill-conditioned pixels.

**File and screenshots**

N/A

**Environment**

 - Python [3.7]
 - Version [v1.9.19]

**Additional context**

N/A

Changed files:
src/psd_tools/composite/blend.py

diff --git a/src/psd_tools/composite/blend.py b/src/psd_tools/composite/blend.py
index 9f7dfa9..009534b 100644
--- a/src/psd_tools/composite/blend.py
+++ b/src/psd_tools/composite/blend.py
@@ -40,7 +40,7 @@ def color_dodge(Cb, Cs, s=1.0):
     B[Cs == 1] = 1
     B[Cb == 0] = 0
     index = (Cs != 1) & (Cb != 0)
-    B[index] = np.minimum(1, Cb[index] / (s * (1 - Cs[index])))
+    B[index] = np.minimum(1, Cb[index] / (s * (1 - Cs[index] + 1e-9)))
     return B
 
 
@@ -48,7 +48,7 @@ def color_burn(Cb, Cs, s=1.0):
     B = np.zeros_like(Cb, dtype=np.float32)
     B[Cb == 1] = 1
     index = (Cb != 1) & (Cs != 0)
-    B[index] = 1 - np.minimum(1, (1 - Cb[index]) / (s * Cs[index]))
+    B[index] = 1 - np.minimum(1, (1 - Cb[index]) / (s * Cs[index] + 1e-9))
     return B
 
 
@@ -162,7 +162,7 @@ def divide(Cb, Cs):
     Looks at the color information in each channel and divides the blend color
     from the base color.
     """
-    B = Cb / (Cs + 1e-6)
+    B = Cb / (Cs + 1e-9)
     B[B > 1] = 1
     return B
 
@@ -199,7 +199,7 @@ def _rgb2cmy(C, K):
     K = np.repeat(K, 3, axis=2)
     color = np.zeros((C.shape[0], C.shape[1], 3))
     index = K < 1.
-    color[index] = (1. - C[index] - K[index]) / (1. - K[index])
+    color[index] = (1. - C[index] - K[index]) / (1. - K[index] + 1e-9)
     return color
 
 
@@ -262,11 +262,11 @@ def _clip_color(C):
 
     index = C_min < 0.
     L_i = L[index]
-    C[index] = L_i + (C[index] - L_i) * L_i / (L_i - C_min[index])
+    C[index] = L_i + (C[index] - L_i) * L_i / (L_i - C_min[index] + 1e-9)
 
     index = C_max > 1.
     L_i = L[index]
-    C[index] = L_i + (C[index] - L_i) * (1 - L_i) / (C_max[index] - L_i)
+    C[index] = L_i + (C[index] - L_i) * (1 - L_i) / (C_max[index] - L_i + 1e-9)
 
     # For numerical stability.
     C[C < 0.] = 0
@@ -294,7 +294,7 @@ def _set_sat(C, s):
 
     index = index_mid & index_diff
     B[index] = C_mid[index] - C_min[index] * \\
-        s[index] / (C_max[index] - C_min[index])
+        s[index] / (C_max[index] - C_min[index] + 1e-9)
     index = index_max & index_diff
     B[index] = s[index]